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 :: react native update state array of objects 
Javascript :: select jquery display none 
Javascript :: 100 day javascript challenge 
Javascript :: linking open app settings 
Javascript :: adding methods to objects javascript 
Javascript :: setinterval react 
Javascript :: error first line of nextjs file 
Javascript :: image to base64 js 
Javascript :: how i do button when click open a new tab in react 
Javascript :: filter object array 
Javascript :: 1 line password strength checker jquery 
Javascript :: nodejs sequelize find 
Javascript :: moment js 
Javascript :: javascript export 
Javascript :: javascript select audio device 
Javascript :: @output() angular 
Javascript :: accesing jest from bin 
Javascript :: Return a Sorted Array Without Changing the Original Array 
Javascript :: mongoose limit skip 
Javascript :: js retrieve form data 
Javascript :: gettwofactorauthenticationuserasync returns null 
Javascript :: add kendo ui dropdown to angular 
Javascript :: js code to accept all linkedin requests 
Javascript :: multiselect_3 
Javascript :: js how to get element csswidth 
Javascript :: angular turn text into input 
Javascript :: javascript coding challenges with solutions 
Javascript :: acer swift 5 
Javascript :: material ui flex direction 
Javascript :: express routers 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =