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

can anyone help me with this ?

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 ?

if choose the second way how to i insert them

You can use | (or)

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

it didnt work now it doesnt accept any of them !??!

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

thank you so much for your answer :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.