javascript - other ways to write regular expression -
are there other ways can write regular expression?
for
var pattern = /^(1[-\.\s])?([{]?\d{3})?[)]?\)?[-. ]?(\d{3})[-. ]?(\d{3})[-. ]?(\d{4})$/;
"use strict"; var $ = function(id) { return document.getelementbyid(id); }; var validatephone = function() { var phone = $("phone").value; //var pattern = /^\d{3}-\d{3}-\d{4}$/; var pattern = /^(1[-\.\s])?([{]?\d{3})?[)]?\)?[-. ]?(\d{3})[-. ]?(\d{3})[-. ]?(\d{4})$/; // 1-999-999-9999 var isvalid = pattern.test(phone); $("message").firstchild.nodevalue = (isvalid) ? "valid phone number" : "invalid phone number"; }; window.onload = function() { $("validate").onclick = validatephone; $("phone").value = ""; // set default phone number };
i know validates phone number lets 1-111-111-1111,
but there other ways recreate code make have same features?
Comments
Post a Comment