Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to write a regular expression which will accept 11 digit strat from 07 (LIKE 07123456789) or can accept NONE, and I am storing this regex in my DB 


What I have tried:

(^[Nn][Oo][Nn][Ee]$)|^07\d{9}$
Posted
Updated 12-May-18 0:26am
Comments
GKP1992 11-May-18 8:09am    
What is the problem with the one you came up with? The only thing I see is that your regex can accept "None" irrespective of the case of the letters. If you want only "NONE" specify it literally.

Try:
^(NONE)|(07\d{9})$


If you want to use regular expressions, get a copy of Expresso[^] - it's free, and it examines and generates Regexes.
 
Share this answer
 
v2
What is the problem with this RegEx ?
The RegEx is matching 'none' and '07345678901'
-----
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[^]
RegExr: Learn, Build, & Test RegEx[^]
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
 
Plz Use
^(NONE)|(07\d{9})$
 
Share this answer
 

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