Click here to Skip to main content
15,910,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Plese tell me the code for regular expression which allows only:
- numbers
- alphabets
- underscore
Posted
Updated 7-Aug-13 23:16pm
v3

try this one

HTML
"^[a-zA-Z0-9_]*$"



you can find link below

http://stackoverflow.com/questions/336210/regular-expression-for-alphanumeric-and-underscores[^]

regards...:)
 
Share this answer
 
v2
Comments
16Sonali 8-Aug-13 4:40am    
Thanks a lot!!!!
Joezer BH 8-Aug-13 4:42am    
The above regex needs some fixes to suit your question...
e.g. it will also catch spaces, and it will not catch lowercase chars (unless he uses IgnoreCase), see my optional solution
Dholakiya Ankit 8-Aug-13 4:50am    
welcome
Joezer BH 8-Aug-13 5:11am    
Why don't you fix your regex Ankit?
Your post is as it is, is misleading - Did you read my post above?

Dholakiya Ankit 8-Aug-13 5:44am    
actually i was about to change but she have accepted it means she get it and she must have tested it thats why i dont change it maimonides
C#
string pattern = "^[a-zA-Z0-9_]*$";


See Regex Quick Reference[^]
Learn Regular Expressions (RegEx) with Ease[^]
 
Share this answer
 
For unlimited alpha numeric and numeric and underscore you can enter
Reg exp = "/^[A-Za-z0-9_]*$/";
or
For specific length alpha numeric and numeric and underscore you can enter
Reg exp = "/^[A-Za-z0-9_]{min length,max length}$/";
 
Share this answer
 
Comments
16Sonali 12-Aug-13 2:24am    
Hi,
When I enter special character in textbox in gridview it wont allow but when clicks on cancel button giving below erro......

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500
16Sonali 12-Aug-13 2:36am    
when clicks on cancel button..it is not cancelled....validation fires for special character...but grid should be in default position......

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900