Sunday, May 8, 2011

REGULAR EXPRESSION JAVA SCRIPT

REGULAR EXPRESSION TO ALLOW ONLY 1 TO 4 DIGIT NUMBER
--------------------------------------------------------
function validateRollNO(field){

var data=field.value.trim();
var regex=/^\d{1,4}$/;
flag=regex.test(data);
var inv=document.getElementById("startingInventory").value;
alert(" RollNO : "+ data + " : "+regex.test(data));
}

REGULAR EXPRESSION TO ALLOW ONLY FOUR DIGIT NUMBER
---------------------------------------------------
function validateRollNo(field){
var data=field.value;
var data=data.trim();
var regex=/^\d{4}$/;
alert(" RollNo : "+ data + " : "+regex.test(data));
}

REGULAR EXPRESSION TO ALLOW ONLY ALPHABETS
--------------------------------------------

function validateName(field){
var data=field.value;
var data=data.trim();
var regex=/^([a-zA-Z])+$/
alert("Name: " + data + " : "+regex.test(data));

}


REGULAR EXPRESSION TO ALLOW ONE OR MORE ALPHABETS AND 1 TO 3 DIGIT NUMBERS AT THE END
-------------------------------------------------------------------------------------
function validateID(field){
var data=field.value;
var data=data.trim();

var regex=/^([a-zA-Z])+(\d{1,3})$/
alert("ID : " +data + " : "+regex.test(data));
}

No comments:

Post a Comment