What is the Regular Expression Validator for only Letters and Numbers in asp.net?
I need to enter only 0-9,a-z and A-Z. I don’t want to allow any special characters single or double quotes etc. I am using asp.net 3.5 framework.
I tried ^[a-zA-Z0-9]+$ and ^[a-zA-Z0-9]*$. They are not working.
Any help will be appreciated.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Try the following.
^[a-zA-Z0-9]+$
go to this example and also alphanumerics for more
then try this
^[a-zA-Z0-9]*$
If length restriction is necessary use
^[a-zA-Z0-9]{0,50}$
This will match alphanumeric strings of 0 to 50 chars.
Method 2
you can try this….
^[a-zA-Z0-9]+$
see more info at here
Method 3
You can define a regular expression as follows,
Regex myRegularExpression = new Regex(" b^[a-zA-Z0-9]+$b");
be sure to include System.Text.RegularExpression
and then use the Regex to match it with your user-control as follows,
eg : if your user-control is a textbox
myRegularExpression.isMatch(myTextBox.Text);
Method 4
Dear English speaking people. With all due respect. A-Z are not the only letters in the world. Please use w instead of [A-Za-z0-9] if you support other languages in your apps
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0