2

I have a from in which user has to enter his phone number.

<input id="username" title="Please enter valid phone number " maxlength="10"  pattern="[0-9]{10}" name="phone"  size="20"
														
												required oninvalid="setCustomValidity('Please enter a valid phone number.')"    onchange="try{setCustomValidity('')}catch(e){}" >

It works fine when validating but only for Numbers. I want the numbers to be specifically starting from 971 as it is limited to UAE numbers only. How can I do that

0

2 Answers 2

2

Try adding that number at first and reduce the occurrence number

pattern="971[0-9]{7}"

<input id="username" title="Please enter valid phone number " maxlength="10"  pattern="971[0-9]{7}" name="phone"  size="20"
														
												required oninvalid="setCustomValidity('Please enter a valid phone number.')"    onchange="try{setCustomValidity('')}catch(e){}" >

Sign up to request clarification or add additional context in comments.

1 Comment

Got it ! Thanks :)
1

If you want it starting specifically from 971, then this will work(assuming 10 digits of number)

971[0-9]{7}

1 Comment

The above answer worked and yours is also correct .. Thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.