Validacion Formas En Javascript
1. Insertar script en la parte de
2. Después del código de la forma insertar otro script
var frmvalidator = newValidator("Nombre de la forma");
frmvalidator.addValidation("Nombre del elemento","req","Please enter your First Name");
//Se deben agregar reglas para cada elemento. Por ejemplo: frmvalidator.addValidation("FirstName","maxlen=20",
"Max length for FirstName is 20");
frmvalidator.addValidation("FirstName","alpha");
frmvalidator.addValidation("LastName","req"); frmvalidator.addValidation("LastName","maxlen=20");
frmvalidator.addValidation("Email","maxlen=50");
frmvalidator.addValidation("Email","req");
frmvalidator.addValidation("Email","email");
frmvalidator.addValidation("Phone","maxlen=50");
frmvalidator.addValidation("Phone","numeric");
frmvalidator.addValidation("Address","maxlen=50");
frmvalidator.addValidation("Country","dontselect=0");
//
a. Para cada vez que se agregue una validación:
frmvalidator.addValidation("Nombre del elemento","Regla de validación","Mensaje en caso de error");
3. Table de Reglas de Validación
required
req | The field should not be empty |
maxlen=???
maxlength=??? | checks the length entered data to the maximum. For example, if the maximum size permitted is 25, give the validationdescriptor as "maxlen=25" |
minlen=???
minlength=??? | checks the length of the entered string to the required minimum. example "minlen=5" |
alphanumeric /
alnum | Check the data if it contains anyother characters other than alphabetic or numeric characters |
num
numeric | Check numeric data |
alpha
alphabetic | Check alphabetic data. |
email | The field is an email field andverify the validity of the data. |
lt=???
lessthan=??? | Verify the data to be less than the value passed. Valid only for numeric fields.
example: if the value should be less than 1000...
Regístrate para leer el documento completo.