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 :: javascript set to array 
Javascript :: how to change size of image js 
Javascript :: set image size phaser 
Javascript :: generating random number in javascript 
Javascript :: get all global variables javascript 
Javascript :: Object.hasOwnProperty.call 
Javascript :: How to hthe amount of users online in discordjs 
Javascript :: access selected option in jquery 
Javascript :: nextjs multer rename file 
Javascript :: index of value in array 
Javascript :: jquery set input value 
Javascript :: find max days of month js 
Javascript :: how to delete element in list javascript 
Javascript :: difference between statement and expression 
Javascript :: javascript url check 
Javascript :: regular expression for thousand separator 
Javascript :: Error: While trying to resolve module `@apollo/client` from file 
Javascript :: add id attribute to jQuery steps 
Javascript :: js string times 
Javascript :: access to xmlhttprequest has been blocked by cors policy react 
Javascript :: C:fakepath fileupload 
Javascript :: how to clone array in js 
Javascript :: jquery add event after page load 
Javascript :: Check if user logged in Wordpress through JS 
Javascript :: nodejs mysql getting the id of an inserted row 
Javascript :: detect if two line segments intersect each other javascript 
Javascript :: javascript scroll to top 
Javascript :: javascript log html element as dom object 
Javascript :: javascript radio button value if checked 
Javascript :: javascript indexof 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =