Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi everyone,

I need mandatory filed regular expression syntax.

Please help any one.

What I have tried:

Am tried this one ^[\w]{1}$

But its allowed only one character. more than one character failed.
Posted
Updated 15-May-17 10:02am

Am tried this one ^[\w]{1}$

But its allowed only one character. more than one character failed.

That's because that is exactly what you told it to do: {1} means "exactly one of" - and is redundant, as is most of that Regex, which reduces to:
^\w$


If you want one or more, then try
^\w+$

If you want 4 then try
^\w{4}$

If you are going to play with regular expressions, get a copy of Expresso[^] - it's free, and it examines and generates Regexes.
 
Share this answer
 
Comments
rkganapathy 16-May-17 2:37am    
Hi,
Any other option to allow special character. Because above solution not allow to special character.
If you want one or more, then try

^[\w]{0,}$
 
Share this answer
 
Comments
rkganapathy 16-May-17 2:24am    
Its not working. show always true.
Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
 
Share this answer
 
Finally ,

I got solution from this link

Regular Expressions to Check for Mandatory Fields[^]
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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