I'm validating a password that must be letters and digits with at least one digit and one upper case letter. I am using the following RegEx expression to do so:
(?=(^[a-zA-Z0-9]{6,16})$)(?=.*\d)(?=.*[A-Z])
Using this pattern, the password "Valid101" should be valid and it worked as expected at both A Better .NET Regular Expression Tester and REGEX TESTER. But, when I use it in my ASP.NET user control's RegularExpressionValidator it wrongly decides that password "Valid101" is not valid.
I'm hoping someone could suggest what might be wrong.
The pattern you have only consists of zero-width assertions, of lookaheads. They do not consume the text they match, so the match value after the regex matches is an empty string. The RegularExpressionValidator requires a full string match (i.e. the string matched should be the whole input string).
So, instead of (?=(^[a-zA-Z0-9]{6,16})$)(?=.*\d)(?=.*[A-Z]) use
^(?=.*\d)(?=.*[A-Z])[a-zA-Z0-9]{6,16}$
It will assure there is a digit and an uppercase ASCII letter in the string, and then will match (consume) 6 to 16 ASCII letters and digits.
Related
I need a Validation Expression to validate an Egyptian mobile number as an input in my form.
Egyptian Mobile Number:
must Contain 11 Digits
must Begin with '01'
the third digit must be either '2' or '1' or '0'
Do you need to support starting '+' characters, spaces or '-' signs inside your phone number? If you don't and you need to support just exact what you said then you can use this pattern:
"^01[0-2][0-9]{8}$"
I'm doing a validation in asp.net textbox, and the textbox only allows user to input number
i.e.
valid numbers:
1234
12.345
12,345,678.231
12,345,678
invalid numbers:
-1234
12.23.45.67
12,
12,34,56
12,345,6
I'm trying to use a regex to validate the user's input on client side with the below regex:
^(?=.+)(?:[1-9]\d*|0)?(?:\.\d+)?$
The problem is:
the above regex only consider below as valid:
1234
12.345
How to modify the above regex to check if the thousand separator being entered into the correct place or not?
this seems to work ^\d+(,\d{3})*(\.\d+)?$
Demo
Let's assume there's a text box somewhere on the page. Users can enter any number of any length, with spaces, hyphens, parentheses, etc. to define groupings. The system returns a list of what kinds of numbers that specific format could match. That is, an input of "111-11-1111" would return, among anything else applicable, "Social Security Number"; an input of "(111) 111-1111" would return "Canadian/American phone number"; an input of "1111 1111 1111 1111" would return "Credit card".
The implementation of this would be trivial, but is there a giant list out there of different number formats?
I think you need to write regular expressions for each type of number and if that regular expression matches than return the type name. You can find lots of regular expressions for SSN, phone number and credit card number on internet.
Check this thread for phone number regular expression.
Phone Number Regular Expression
Is it possible use a regular expression validator for a textbox which accepts either user email or phone number (11 digits number which begins with 09) ?
so one regex is needed which accepts one of two cases, email or number.
For Email : "\w+([-+.']\w+)#\w+([-.]\w+).\w+([-.]\w+)*"
[0][9][0-9]
I have asp.net(c#) web form with html input text(first name) how i can check if string contains symbols, numbers, unicode text, space with c#
or its more easier with html?
I want to user entered only first name
This regular expression will only match on one or more ASCII characters:
^[A-Za-z]+$
You can use the above in either Javascript or .NET.