Click here to Skip to main content
15,509,806 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi I need regex that allow only alphanumeric, hyphen, underscore and space.

pls help me.
Posted
Updated 22-Jun-14 23:02pm
v2
Comments
Peter Leow 23-Jun-14 6:52am    

Your original question did not mention space. It is not right to alter the question after we have given the correct answer to the original question. I considered this as an abuse.

Yogesh Kumar Tyagi 23-Jun-14 8:22am    
sorry, but my actual requirement is alphanumeric, hyphen, underscore and space. so i edit my question

Try this:
^[a-zA-Z\d-_]+$

Read more: The 30 Minute Regex Tutorial[^]
 
Share this answer
 
Comments
Yogesh Kumar Tyagi 23-Jun-14 4:00am    
Hello sir this pattern not allow space
Peter Leow 23-Jun-14 6:50am    
Your original question did not mention space. It is not right to alter the question after we have given the correct answer to the original question.
Try:
^[\w-_]+$
 
Share this answer
 
Comments
Yogesh Kumar Tyagi 23-Jun-14 4:01am    
Hello sir this pattern not allow space
i use

^[A-Za-z_-][A-Za-z0-9_-]*$
 
Share this answer
 
I solve it

New Expression is:

@"^[\w\-\s]+$"
 
Share this answer
 
v2

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