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

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

c# - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind -