Number validation using javascript regular expressions


Below is the code which can be used to validate numbers using javascript regular expressions

//Numeric validations
function numericvalidation(number)
{
    var numericExpression = /^[0-9]+$/;
    if(number.match(numericExpression)) {
        number= "1";
      
        return true;
    }
  
    if(number!="1"){
      
        return false;
    }
}


Usage:

var num=document.getElementById("age").value;

 if( numericvalidation(num)==false)    {
        alert("Please enter valid age");
        return false;
    }


1 comment:

  1. Slots Casino Online - No deposit bonus - Casino Online
    The Online febcasino Slots Casino 카지노 has an impressive variety of slots games and more. kadangpintar This casino site is equipped with a lot of different slot games such as video slots

    ReplyDelete