Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript Validating the Phone Number

// program to validate the phone number
function validatePhone(num) {
    // regex pattern for phone number
    const re = /^(?([0-9]{3}))?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/g;
    // check if the phone number is valid
    let result = num.match(re);
    if (result) {
        console.log('The number is valid.');
    }
    else {
        let num = prompt('Enter number in XXX-XXX-XXXX format:');
        validatePhone(num);
    }
}

// take input
let number = prompt('Enter a number XXX-XXX-XXXX');

validatePhone(number);
Comment

validate phone number javascript

// Commonly used regular expression

// Check 2-9 characters, false if not matched, true if matched
const validateName = (name) => {
   const reg = /^[u4e00-u9fa5]{2,9}$/;
   return reg.test(name);
};
// Verify phone number
const validatePhoneNum = (mobile) => {
   const reg = /^1[3,4,5,6,7,8,9]d{9}$/;
   return reg.test(mobile);
};
// Check passwords consisting of 6 to 18 uppercase and lowercase alphanumeric underscores
const validatePassword = (password) => {
   const reg = /^[a-zA-Z0-9_]{6,18}$/;
   return reg.test(password);
};
Comment

js validate phone number

/^[+]?[(]?[0-9]{3}[)]?[-s.]?[0-9]{3}[-s.]?[0-9]{4,6}$/im
Comment

validate mobile number in javascript

var val = number.value
if (/^d{10}$/.test(val)) {
    // value is ok, use it
} else {
    alert("Invalid number; must be ten digits")
    number.focus()
    return false
}
Comment

js phone number validation

^(?!.*911.*d{4})((+?1[/ ]?)?(?![(. -]?555.*)( ?[2-9][0-9]{2} ?) ?|(+?1[./ -])?[2-9][0-9]{2}[./ -]?)(?!555.?01..)([2-9][0-9]{2})[./ -]?([0-9]{4})$
Comment

PREVIOUS NEXT
Code Example
Javascript :: close exit app react native 
Javascript :: yarn create strapi-app 
Javascript :: yeet 
Javascript :: if document is loaded 
Javascript :: jstl replace 
Javascript :: set autofocus javascript 
Javascript :: codeigniter raw query 
Javascript :: jquery check if string contains specific word 
Javascript :: regex find lines containing two strings 
Javascript :: javascript get last day of month 
Javascript :: regex match everything before string 
Javascript :: pagecontrol 
Javascript :: ReferenceError: fetch is not defined 
Javascript :: rimraf node_modules 
Javascript :: jquery select element with data 
Javascript :: loop on objects js 
Javascript :: mongoose timestamps 
Javascript :: javascript timestamp to relative time 
Javascript :: regex for time in hh:mm:ss 
Javascript :: get height component react 
Javascript :: javascript change class of item 
Javascript :: npm ERR! peer dep missing: @babel/core@^7.13.0, required by @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@7.14.5 
Javascript :: how to use current data in javascript 
Javascript :: if radio checked jquery 
Javascript :: javascript play sound onclick 
Javascript :: javascript get last character in string 
Javascript :: material ui input placeholder color 
Javascript :: ref schemas mongoose error 
Javascript :: html tag run only after whole page is loaded 
Javascript :: disable input angular 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =