Tuesday, June 14, 2011

Making of Alphanumeric input using Regular Exp

In Javascript,

        //replace(/[^a-zA-Z.-]/g,'').toUpperCase().;   //Removes other than the list of inputs
        //replace(/^(-)[A-Z.-]+/g,'$1');  //Only allows single -
        //replace(/^[.]/g,'');    //Don't allow . as a first character
        //replace(/^([A-Z.]+)[-]+/g,'$1');    //Remove all the - inbetween the string
        //replace(/[.]+/g,'.');   //Removes more than one occurrences of .
       
        obj.value = obj.value.replace(/[^a-zA-Z.-]/g,'').replace(/^(-)[A-Z.-]+/g,'$1').replace(/^[.]/g,'').replace(/^([A-Z.]+)[-]+/g,'$1').replace(/[.]+/g,'.');


No comments:

Post a Comment