I am using regular expression to validate the mobile number with the following criteria:
- Maximum of 12 numbers.
- It should start with Zero.
- Will allow only one space (at a non-defined point)
- Followed by an optional extension number of up to five digits in length, not including the # sign
My Regular Expression looks like below: (I have tested this with “rubular” tester)
^((0((?=\d* \d*#)[\d ]{,11})(#\d{,5})?)|(0(?:\d{,10})(#\d{,5})?)|(0((?=\d* \d*$)[\d ]{,11})))$
But it’s not working in .net regular expression engine.
Can someone tell me, in the above one which part doesn’t work with .net regular expression engine? and if I can change anything in the above expression will it work in .Net regular expression engine?
The only problem in your regex is that you are not specifying the starting range anywhere.. so it should be
{0,11}or{1,11}not{,11}You can also use this simplified regex
\Smatches any character that is not space(\S*[\s]\S*|\S*)$matches 0 to many non space character followed by a space followed by 0 to many non space characters till end OR it matches all the non space character till end(?=)is apositive lookaheadwhich check if particular pattern occurs and if not it will not match!