我想验证姓名,电话,姓氏,电子邮件,但是当我想提交时,它不起作用..我试图改变我的表情,但没有。
$(document).ready(function(){
$('#ok').on('click',function(){
var name = $('#txtNombre').val();
var surname = $('#txtApellido').val();
var email = $('#txtCorreo').val();
var phone = $('#txtTelefono').lengh;
if(name == null || name.length == 0 || /^[a-zA-Z ]+$/.test(name)){
$("#txtNombre").css('border-color','red');
}else{
$("#txtNombre").css('border-color','');
}
if(surname == null || surname.length == 0 || /^[a-zA-Z ]+$/.test(surname)){
$("#txtApellido").css('border-color','red');
}else{
$("#txtApellido").css('border-color','');
}
if(email == null || email.length == 0 || /^[a-zA-Z0-9._-]+@[A-Za-z0-9]+.(com|com.mx|es|edu.mx)$/.test(email)){
$("#txtCorreo").css('border-color','red');
}else{
$("#txtCorreo").css('border-color','');
}
if(phone == null || phone.length == 0 || /^[0-9]+$/.test(phone)){
$("#txtTelefono").css('border-color','red');
}else{
$("#txtTelefono").css('border-color','');
}
});
$('#cancel').on('click',function(){
$('#txtNombre, #txtApellido, #txtCorreo, #txtTelefono').val('');
$('#txtNombre, #txtApellido, #txtCorreo, #txtTelefono').css('border-color','');
});
});