Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression Validator for Letters and Numbers only

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.

like image 588
David John Avatar asked Nov 11 '11 11:11

David John


People also ask

How do you check if a string only has letters and numbers?

To check whether a String contains only unicode letters or digits in Java, we use the isLetterOrDigit() method and charAt() method with decision-making statements. The isLetterOrDigit(char ch) method determines whether the specific character (Unicode ch) is either a letter or a digit.

How do you only use numbers in regular expressions?

To get a string contains only numbers (0-9) we use a regular expression (/^[0-9]+$/) which allows only numbers.

How do you check if a string contains only alphabets and numbers in JavaScript?

To check if a string contains only letters and numbers in JavaScript, call the test() method on this regex: /^[A-Za-z0-9]*$/ . If the string contains only letters and numbers, this method returns true . Otherwise, it returns false .


1 Answers

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.

like image 190
Sai Kalyan Kumar Akshinthala Avatar answered Oct 05 '22 17:10

Sai Kalyan Kumar Akshinthala