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

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 :: networkx get nodes 
Javascript :: javascript pop object from array 
Javascript :: jsx return greatest number between two numbers 
Javascript :: how to get firebase document id angular 
Javascript :: switch window 
Javascript :: nuxt auth user info 
Javascript :: events onclick 
Javascript :: date object js 
Javascript :: redirect to dashboard after login in vue 
Javascript :: moment.js format 
Javascript :: angular create injectable 
Javascript :: sequelize findall 
Javascript :: json to yaml converter 
Javascript :: js random number array 
Javascript :: search with multiple field in node js mongodb 
Javascript :: @input in angular 
Javascript :: when programmers net goes down 
Javascript :: gojs update text 
Javascript :: The .querySelector() Method 
Javascript :: how to add image url in tailwindconfig .js 
Javascript :: pwa cache viewer 
Javascript :: git reset local branch to origin 
Javascript :: change base js 
Javascript :: multiselect 
Javascript :: jquery get id of 3rd parent 
Javascript :: formating decimal hours as hours and minute javascript 
Javascript :: spread operator react 
Javascript :: ejs js 
Javascript :: auth provider react 
Javascript :: get text selection javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =