HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Validating User Input in HTML Control Text Field
Post new topic   Reply to topic    HTML Help Forum Index -> HTML Form
View previous topic :: View next topic  
Author Message
sueolo



Joined: 17 Sep 2004
Posts: 1
Location: Florida

PostPosted: Sun Sep 19, 2004 7:43 am     Validating User Input in HTML Control Text Field Reply with quote

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)?

Thank you.
Corey Bryant
Site Admin


Joined: 15 May 2004
Posts: 8301
Location: Castle Pines North, CO USA

PostPosted: Sun Sep 19, 2004 9:14 am     Reply with quote



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>

The opening FORM tag, something like:
Code:
<form method="Post" action="confirm.asp" onsubmit="return validate(this)">

and then the input field:
Code:
<input type="text" name="Merchant_Email" size="20">
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> HTML Form All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial