Posted: Sun Sep 19, 2004 7:43 am Validating User Input in HTML Control Text Field
How do I validate user input in a HTML Control Text Field?
Example 1: If the required text field asks for the user's email address and the user does not input the "@" sign, how do I check for this?
Example 2: If the required text field is left blank, how do I check for this?
How can I alert the user by maybe putting an asterisk next to the field (in addition to returning focus to the field)?
Joined: 15 May 2004 Posts: 8199 Location: Castle Rock CO USA
Posted: Sun Sep 19, 2004 9:14 am
You are going to have to use some type of Javascript. In the HEAD:
Code:
<script language="JAVASCRIPT">
<!--
function isMerchant_Email( strValue) {
var objRegExp = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
return objRegExp.test(strValue);
}
function validate(theForm){
if(theForm.Merchant_Email.value == ""){
alert('Please enter a valid E-mail address to submit the form');
theForm.Merchant_Email.focus();
return false;
}
if(!isEmail(theForm.Merchant_Email.value)){
alert('Please enter a valid E-mail address to submit the form');
theForm.Merchant_Email.select();
theForm.Merchant_Email.focus();
return false;
}
return true;
}
// -->
</script>
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum