Required Regex for mobile number validation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2020 10:51 AM
Hi Team,
i need regex for validating mobile number. Its simple that we need to validate 1 variable when user gives his mobile number it should start with country code (example : +91,+46). If not it should show an alert that your number is not valid as its missing with country code.
I have checked in previous community questions but for country code validation i am not able to find. Need assistance.
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2020 11:04 AM
Hi Anand,
Please try the below regex.
/^(\+)([1-9]{2})(\s)(\d{10})$/g
Live test here - Phone Number with country code validation
Hope that helps!
Regards,
Muhammad
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2020 11:05 AM
It is not exact strict but it will help your purpose.....
^\+[1-9]{1}[0-9]{3,14}$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2020 11:24 AM
I am using below code. But i am getting common alert and even if i give any value or remove 1 number. But when i try to submit with out + sign. it should not allow me to submit.
Did i miss something here?
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading || newValue == ''){
return;
}
var pattern = /^(\+)([1-9]{2})(\s)(\d{10})$/g;
if(!pattern.test(newValue)){
alert('Phone enter a valid phone number');
g_form.setValue('u_number', '');
}}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2020 11:32 AM