if the visitor fills out a field phone then allowed only enter numbers. and if the visitor fills out a field phone then allowed only enter email.
Check this out
function validateForm(){
var x = document.getElementById('name');
var email = document.getElementById('email');
var num = document.getElementById('number');
var size = document.getElementById('size');
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var atpos=email.value.indexOf("@");
var dotpos=email.value.lastIndexOf(".");
if (x.value == null || x.value == "") {
alert("Please Enter your name");
x.focus();
x.style.background = 'Yellow';
return false;
}
if(!filter.test(email.value)){
alert('Please provide a valid email address');
email.focus();
email.value="";
return false;
}
if(num.value == null || num.value == ""){
alert('Please enter your mobile number');
num.focus();
return false;
}
if(isNaN(num.value)){
alert('Please enter a valid number');
num.focus();
num.style.background = 'Yellow';
return false;
}
}
Demo @: http://jsfiddle.net/e4E7D/2/
0
solved Validation Form with PHP or Javascript [closed]