0

Hi

i tried this regular expression ^(?:\00|9)[. ()-]*(?:\d[. ()-]*){8,14}$to enter a phone number in a text field ,but it didnt work like i wanted .

what i want the rule to be is if the phone number starts with 9 then the length would be 8 digits, but if the phone number starts with 00 it would 14 in length on the same regular expression , the expression i found takes all the cases, like if it starts with 9 it could be 14 in length and vice versa !

the problem is that the phone number takes two forms in one input if this was on 2 input fields this would be much easier.

can any one help me with this ?

thats my code ... i used form validation to validate my form .
also if i can expand the rule a bove like this if i want to start with 123 and length 20 or any like this .

<input type="text" class="txt" id="mob_num"  data-validation="custom"   data-validation-regexp="^(?:\00|9)[. ()-]*(?:\d[. ()-]*){8,14}$"  data-validation-error-msg="please enter the correct number" />

<script> $.validate(); </script>

Thank you :D

Edited by fedaa91

2
Contributors
6
Replies
36
Views
3 Years
Discussion Span
Last Post by fedaa91
0

so i tried this to combine both conditions
^(?:\+|00{14}|9{8})[. ()-]*(?:\d[. ()-]*)$
and those 2
^(?:\9)[. ()-]*(?:\d[. ()-]*){8}$ -->starts with 9 length is 8
^(?:\00)[. ()-]*(?:\d[. ()-]*){14}$-->starts with 00 length is14

if choose the second way how to i insert them in the data-validation-regexpattribute as two expressions ?

0

between the two expressions
like this

<input type="text" class="txt" id="mob_num"  data-validation="custom"   data-validation-regexp="^(?:\9)[. ()-]*(?:\d[. ()-]*){8}$ |^(?:\00)[. ()-]*(?:\d[. ()-]*){14}$"  data-validation-error-msg="please enter the correct number" />

i will try this ,thanks

1

it worked i was having a space not in the correct place

thank you so much for your answer :D

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.