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

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

PREVIOUS NEXT
Code Example
Javascript :: firebase for vue project 
Javascript :: nested objects javascript 
Javascript :: importing json file in javascript 
Javascript :: C:fakepath fileupload 
Javascript :: prevent blur event on click 
Javascript :: jspdf save in server 
Javascript :: javascript replace all spaces 
Javascript :: forloop in js 
Javascript :: how to make button disabled in jquery before send 
Javascript :: chrome.storage.local.remove example 
Javascript :: bootstrap 4 navbar-collapse not working angular 
Javascript :: js convert array of arrays to array 
Javascript :: find largest number from an array in JavaScript 
Javascript :: javascript check if element is visible on screen 
Javascript :: javascript ternary 
Javascript :: how to make form in javascript 
Javascript :: img src in react js 
Javascript :: addclass removeclass jquery 
Javascript :: ajax onchange dropdown 
Javascript :: javascript radio button value if checked 
Javascript :: javascript array move element one position 
Javascript :: javascript if browser out of focus 
Javascript :: how to set css variables in javascript 
Javascript :: js find index in list 
Javascript :: redirect all request http to https express js 
Javascript :: Remove Duplicates array values in javascript 
Javascript :: rating star jquery 
Javascript :: javascript regex cheat sheet 
Javascript :: axios add no cors 
Javascript :: jquery display modal bs4 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =