How to implement regex for userID field? - android

I have one userID edittext field, here I am allowing alphabets and numbers and '.' and '_' and '#' special characters. But how to restrict only '.' and '_' and '#' in edittext field? I want to restrict like this:
After text only I want to allow those special characters.
Only one time I want to allow those spl characters(don't allow two times like ##,..,__ like this)
end of the userID no spl characters.
test.new_bike sample example for valid.
test..new__bike,........,______,###### like words I won't allow.
please help me,this is my regex
^(([A-Za-z0-9]+\\s{1}[A-Za-z0-9]+)|([A-Za-z0-9._]+))$

Try this one
"^[A-Za-z0-9]+[\\.\\#\\_]{0,1}[A-Za-z0-9]+[\\.\\#\\_]{0,1}[A-Za-z0-9]+[\\.\\#\\_]{0,1}[A-Za-z0-9]+$"

Related

Regex with numbers and alphabets mandatory, special characters optional

In my application edittext value need at least one digit and one alphabet is mandatory, and some special characters are optional i.e ".-", like any whare in the string.
For example ram123-. or r_m-12.m or .--ram123 or ram123.-_.
For this I need regex. I have already tried with this one
str_userId.matches("[A-Za-z0-9]*+[?.?_?-]")
But not working. Here how to add special characters are optional.
Thanks, In Advance
You could use a positive lookahead (?= to assert at least one occurrence of a-z and after that match at least a single digit [0-9].
Before and after matching the digit, you could add the . _ and - to the character class [A-Za-z._-]* and repeat it 0+ times.
Note that a character class matches on of the listed characters. This notation [?.?_?-], which could be written as [?._-] would also match a question mark instead of making the others optional
^(?=[^a-z\n]*[a-z])[A-Za-z._-]*[0-9][A-Za-z0-9._-]*$
Regex demo

format edittext input price format

When we work with the currency we need to use ',' separator in appropriate places . For example 1500 as 1,500.
I have a issue. My applications require formatting the EditText's value while typing. I.E., a number that needs to be formatted with decimal and thousands separators. Example, I input 123456789, the EditText display 123.456.789.
How to I do this issue ? Thank all.

InputFilter Pattern isn't allowing decimal

I want a user to be able to input numbers such as the following.
Valid:
~0
~0.00
~12.34
~301.7
~4
Invalid
~01
~3.001
In short, it allows decimal numbers up to two decimal places.
This is what I've been trying to use
Pattern mPattern = Pattern.compile("|(0|[1-9]+[0-9]*)(\\.[0-9]{1,2})?");
When I try to type a "." in the field, it won't let me.
I think the problem is that your validation pattern needs to match the input as you are entering it. In your case, as soon as you type in the ".", your entry is invalid. For example, if you are trying to enter 1.23, when you are entering the decimal point your entry becomes 1., which does not match your regexp.
Try replacing {1,2} with {0,1,2} in your expression to allow a trailing ".".

EditText field adding backslashes to create surrogate pair

I am using an EditText field to capture a password from the user. The password is saved as a String. It is later used in a hashing function. My problem is that special characters such as "\" are saved as surrogate pairs within a String class, like "\\". As a result, passwords that are entered with special characters like "\" are failing in the hash function (they are getting hashed as "\\". How do I solve this?
Thank you!
Edit - turns out that the only special character out of the following that gets mangled (ie String class adds an additional backslash) is (indeed) "\":
some special characters: !"#$%&'()*+,-./:;<=>?#[\]^_`{|}~
Solving this by substituting a character array for the Java String throughout my code would be the correct way to go, but its extremely messy in this app. So, I am going to simply swap out "\\" for "\" within the password hash function.

EdiText Android InputType

Looking on input types that a EditText view can have i seen "textPersonName" and i try to search a way to (if possible) split name and surname using maybe a method like editText.getName. My question is exist a method of edittext that splits name and surname in edittext? And if don't exist the best way is to use split or else?
The textPersonName is just a style option, for instance it capitalizes the first letter of each word. It won't help you distinguish first and last names. However you can search for spaces, for instance:
String[] names = editText.getText().toString().split(" ");
The Array of Strings will have each name in a different String. If the user entered: John Doe you would have "John" in names[0] and "Doe" in names[1].

Categories

Resources