Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript masking if input matches patter

document.getElementById("phone").addEventListener("keyup", function(){
    // restart the match
    this.value = this.value.replace(/s/g, "");
    // Assess the amount needed
    var v = this.value.match(/(d)(d{1,3})?(d{1,2})?(d+)?/);
    if(v){
      // Save the desired value depending on its existence
      v =  (v[1]?v[1]+(v[2]?" "+v[2]+(v[3]?" "+v[3]+(v[4]?" "+v[4]:""):""):""):"");
      // and yea!
      this.value = v;
    }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: giving the date in protractor 
Javascript :: activejs 
Javascript :: applescript show function keys 
Javascript :: how to create nav tab with javascript with validation to move to the next tab 
Javascript :: javascript es6 quizes 
Javascript :: payfast javascript integration 
Javascript :: js find place value 
Javascript :: advanced data manipulation javascript 
Javascript :: ladder physics javascript 
Javascript :: how to add json datasource in jasperserver 
Javascript :: passport restarting server why 
Javascript :: console log update status bar 
Javascript :: how to access viewmodel in jquery 
Javascript :: tableau javascript 
Javascript :: regex changing before last dot value 
Javascript :: javascript picture delete after time 
Javascript :: how display same paragraph in all pages of website in js 
Javascript :: jquery delete buton 
Javascript :: knex.js insert two rows 
Javascript :: javascript Power of a matrix 
Javascript :: how to use yes no statement with alert in tampermonkey 
Javascript :: make directive to return dropdown values angular 
Javascript :: how to bind a json output result to any new model 
Javascript :: Javascript uninstall dependancy 
Javascript :: specify the own log file name using the property 
Javascript :: javascripte 
Javascript :: convert rgb value in hexadecimal system 
Javascript :: jackson jsonpath 
Javascript :: firebase update return result 
Javascript :: how to send json data to server in android using volley 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =