Ok, explico, pero creo que por lo largo voy a tener que usar varios post, estoy haciendo validaciones para un formulario php algo extenso, y las valido con funciones e if's concatenados con javascript y me baso en las que ponen en este tutorial (
http://www.tizag.com/javascriptT/javascriptform.php), las copio:
validaciones.js (Solo las funciones)
Código:
// Estas son funciones para validar los formularios sacadas del sitio http://www.tizag.com
function notEmpty(elem, helperMsg){
if(elem.value.length == 0){
alert(helperMsg);
elem.focus(); // set the focus to this input
return false;
}
return true;
}
function notPhone(elem, helperMsg){
if(elem.value.length == 14){
alert(helperMsg);
elem.focus(); // set the focus to this input
return false;
}
return true;
}
function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
function isAlphabet(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
function isAlphanumeric(elem, helperMsg){
var alphaExp = /^[0-9a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
function lengthRestriction(elem, min, max){
var uInput = elem.value;
if(uInput.length >= min && uInput.length <= max){
return true;
}else{
alert("Please enter between " +min+ " and " +max+ " characters");
elem.focus();
return false;
}
}
function madeSelection(elem, helperMsg){
if(elem.value == "Please Choose"){
alert(helperMsg);
elem.focus();
return false;
}else{
return true;
}
}
function madeSelectiontype(elem, helperMsg){
if(elem.value == "Select Type..."){
alert(helperMsg);
elem.focus();
return false;
}else{
return true;
}
}
function madeSelectionIMO(elem, helperMsg){
if(elem.value == "Select IMO..."){
alert(helperMsg);
elem.focus();
return false;
}else{
return true;
}
}
function madeSelectiontime(elem, helperMsg){
if(elem.value == "..."){
alert(helperMsg);
elem.focus();
return false;
}else{
return true;
}
}
function madeSelectionoffice(elem, helperMsg){
if(elem.value == "Select Office..."){
alert(helperMsg);
elem.focus();
return false;
}else{
return true;
}
}
function madeSelectionPort(elem, helperMsg){
if(elem.value == "Select Port..."){
alert(helperMsg);
elem.focus();
return false;
}else{
return true;
}
}
function madeSelectionCompany(elem, helperMsg){
if(elem.value == "Select Port..."){
alert(helperMsg);
elem.focus();
return false;
}else{
return true;
}
}
function madeSelectionBrand(elem, helperMsg){
if(elem.value == "Select Brand..."){
alert(helperMsg);
elem.focus();
return false;
}else{
return true;
}
}
function madeSelectionComponent(elem, helperMsg){
if(elem.value == "Select Component..."){
alert(helperMsg);
elem.focus();
return false;
}else{
return true;
}
}
function emailValidator(elem, helperMsg){
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(elem.value.match(emailExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
Continuo en el siguiente thread