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 :: submit form in vue 
Javascript :: Factorial multiplication in javascript 
Javascript :: remove element from array in usestate 
Javascript :: vanilla javascript add class 
Javascript :: docker react 
Javascript :: check if element has specific child javascript 
Javascript :: django jquery 
Javascript :: javascript array flat 
Javascript :: angular 9 form value changes 
Javascript :: find whitespace in string js 
Javascript :: compare two dates using moment 
Javascript :: how to generate unique id in node js 
Javascript :: date js 
Javascript :: email id domain check javascript 
Javascript :: vue js countdown timer 
Javascript :: foreach reverse javascript 
Javascript :: Uncaught TypeError: $(...).DataTable is not a function 
Javascript :: dropzone get response 
Javascript :: prepend to array javascript 
Javascript :: chart.js chart is not defined 
Javascript :: disable a button in javascript 
Javascript :: remove role discord.js 
Javascript :: reverse string js 
Javascript :: javascrip check if string contains substring 
Javascript :: react native app crashes without error 
Javascript :: text inside an image component react native 
Javascript :: createrouter vue 3 history remove Hash 
Javascript :: TypeError: sequelize.import is not a function 
Javascript :: moment js from now 
Javascript :: move element jquery 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =