I need the pattern checking for mobile number in(+971) 556-123456 this format in HTML phone numbers.
Asked
Active
Viewed 2,331 times
-1
-
Possible duplicate of [Validate UAE phone numbers](http://stackoverflow.com/questions/24646890/regular-expression-for-validating-uae-numbers) – Vaulstein Jul 14 '15 at 09:12
-
format is different. – Sasi Rekha Jul 14 '15 at 09:22
-
possible duplicate of [A comprehensive regex for phone number validation](http://stackoverflow.com/questions/123559/a-comprehensive-regex-for-phone-number-validation) – elssar Jul 14 '15 at 09:29
-
is the `(+971)` prefix optional? – cнŝdk Jul 14 '15 at 09:42
-
I think it should be (+971) 55-612-3456,plz Check it once again. – Laxmikant Dange Jul 14 '15 at 10:02
1 Answers
2
I think this is the RegEx you need:
\(\+971\) [0-9]{3}-[0-9]{6}
Here's a live DEMO of it.
And If I am not wrong the +971
prefix is optional so the right RegEx would be:
(\+971)? [0-9]{3}-[0-9]{6}
And this is a live DEMO of it.
EDIT:
If the +971
prefix is not optional and I assume the parentheses are optional, here's the RegEx you need:
\+971\s[0-9]{3}-[0-9]{6}
Make sure you add the \s
to ensure having the space after the +971
prefix.
This is a Working DEMO and you can test it in the above snippet:
<form action="demo_form.asp">
Phone number:
<input class="form-control" pattern="\+971\s[0-9]{3}-[0-9]{6}" name="homeNo" value="+971 555-4144" id="homeNo" required />
<input type="submit">
</form>

cнŝdk
- 31,391
- 7
- 56
- 78
-
971 is not optional and pattern is not working in jsp. pattern = "\(\+971)? [0-9]{3}-[0-9]{6}" maxlength="8" . but pattern is not working. Thanks for your response – Sasi Rekha Jul 15 '15 at 05:38
-
How it doesn't work? What do you get? And if the 971 is not optional you can take a look at my EDIT. – cнŝdk Jul 15 '15 at 07:41
-
I am using in HTML5. if I gave wrong format input, while I am submitting the form, I will get error message. but I am able to submit the form.This is my html 5 code . $(document).ready(function() { $("#homeNo").jqxMaskedInput({ width: '100%', height: '100%', mask: '(+971) 5##-######'}); $('#mobileNo').attr("style","");}); – Sasi Rekha Jul 15 '15 at 08:28
-
-
Here's the HTML code for it: `Phone number:
` I tested it and it works perfectly, take a look at the snippet in my EDIT. – cнŝdk Jul 15 '15 at 09:06 -
yes. its working fine in your code. but I don't know why, its not working in my code. I am using jqwidgets, using that I am using some masking as well.I am not sure, that could be issue. see my code above.Thanks for your response. – Sasi Rekha Jul 16 '15 at 05:56
-
-
-
-
its working fine with the below code: I just removed onvalid and oninvalid functions and its working fine now. Thanks for your effort. Thanks a ton. – Sasi Rekha Jul 20 '15 at 08:32