Skip to content

Instantly share code, notes, and snippets.

@richardprice-1990
Created March 22, 2019 09:58
Show Gist options
  • Save richardprice-1990/4f01f4303e60ebb8c84aef979c6431d6 to your computer and use it in GitHub Desktop.
Save richardprice-1990/4f01f4303e60ebb8c84aef979c6431d6 to your computer and use it in GitHub Desktop.
async mobileValidation(){
//Mobile format +447XXXXXXXXX
const regex_format = /^((\+44)7\d{9})$/
let mobile = this.mobile
if (!mobile) return;
mobile = mobile.replace(/ /g, "");
if (mobile.length == 11 && mobile.substring(0,1) == 0){
mobile = `+44${mobile.substring(1,)}`
}
if (mobile.substring(0, 2) == "44"){
mobile = `+${mobile}`
}
if (regex_format.test(mobile)) {
this.mobile = mobile
} else{
this.mobile = null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment