Skip to content

Instantly share code, notes, and snippets.

@richardprice-1990
Created May 10, 2019 09:50
Show Gist options
  • Save richardprice-1990/32b0e5ea92e5dd45f28b1c7cc4764ad0 to your computer and use it in GitHub Desktop.
Save richardprice-1990/32b0e5ea92e5dd45f28b1c7cc4764ad0 to your computer and use it in GitHub Desktop.
async mobileValidation(){
try{
//Mobile format +447XXXXXXXXX
let regex_format = /^((44)7\d{9})$/
let mobile = this.mobile
if (!mobile) {
this.mobile = "";
return
}
mobile = mobile.replace(/ /g, "");
if (siteConfig[this.site].mobileRegex) {
regex_format = siteConfig[this.site].mobileRegex
} else {
//UK Numbers (attempt to fix)
if (mobile.length == 11 && mobile.substring(0, 1) == 0) {
mobile = `44${mobile.substring(1)}`
}
if (mobile.substring(0, 1) == "+") {
mobile = mobile.substring(1)
}
}
if (regex_format.test(mobile)) {
this.mobile = mobile
} else{
this.mobile = ""
}
}catch(e){
throw(e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment