Validate SA Cell Number with Javascript

function validate(){
var MobileNumber = document.getElementById(“MobileNumber”).value;
var MobileNumberRegEx = /^\+27[78][23467][0-9]{7}/;
if (MobileNumberRegEx.test(MobileNumber)) {
return true;
}else{
alert(“Please enter a valid South African mobile phone number\nin the following format: +27820000000”);
return false;
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: