Getting Started: Form validation implementation in ASP

Source: Internet
Author: User
Tags html form valid email address
Form validation

In the ASP program we often ask users to fill out a form, and then send the button directly sent to us, today this program is to limit the content of the form, and then sent to us.

Just a simple example, I hope to be useful for everyone programming.

HTML form:

<form action= "action.asp" method= "post" name= "MyForm" >
Name and Surname: <br/>
<input type= "text" name= "Nameandsurname" size= "> <br/>
Email: <br/>
<input type= "text" name= "email" size= "> <br/>
Age: <br/>
<input type= "text" name= "Age" size= "3" > <br/>
Gender: <br/>
<select size= "1" name= "gender" >
<option>-Select Gender-</option>
<option value= "Male" >Male</option>
<option value= "Female" >Female</option>
</select> <br/>
<input type= "Submit" value= "Submit" >
</form>

where the check () function is used to detect the contents of the form.

JavaScript functions:

<script language= "JavaScript" type= "Text/javascript" >
function Check () {
var nameandsurname = Document.myform.nameandsurname;
var email = document.myform.email;
var age = Document.myform.age;
var gender = Document.myform.gender;
if (Nameandsurname.value.indexOf ("") = = 1) {
Alert ("Enter your Name and Surname.");
Nameandsurname.focus ();
else if ((Email.value.indexOf ("@") = = 1) | | (Email.value.indexOf (".") = = 1)) {
Alert ("Enter your valid email address.");
Email.focus ();
else if (! (parseint (Age.value) > 0)) {
Alert ("Enter your Age.");
Age.focus ();
else if (Gender.selectedindex = 0) {
Alert ("Select your gender.");
Gender.focus ();
} else {
Document.myform.submit ();
}
}
</SCRIPT>

Put the above JavaScript code in the



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.