These typical form data verified by JavaScript are:
Does the user have filled in the required items in the form?
Is the mail address entered by the user is legal?
Has the user entered a legal date?
Do users enter text in Numeric Field?
Must -fill (or must choose) project
The following functions are used to check whether the user has filled in the required (or required) item in the form. If the must be filled or the option is empty, then the warning box will pop up, and the return value of the function is false, otherwise the return value of the function is true (means that the data is no problem):
Copy code code as follows:
Function value_required (Field, Alerttxt)
{{
with (field)
{{
if (value == null || value == "")
{Alert (Alerttxt); Return false}
else {Return True}
}
}
E-mail verification (verification mailbox)
The following functions check whether the input data conforms to the basic syntax of the email address.
This means that the input data must contain@ symbols and dot numbers (.). At the same time,@ not the first character of the email address, and at least one point number after@ 同时:
Copy code code as follows:
Function value_email (Field, Alerttxt)
{{
with (field)
{{
Apos = value.indexof ("@")
dotpos = value.lastindexof (".")
If (APOS <1 || DOTPOS-APOS <2)
{Alert (Alerttxt); Return false}
else {Return True}
}
}
Example:
Copy code code as follows:
<html>
<head>
<script type = "text/javascript">
Function value_email (Field, Alerttxt)
{{
with (field)
{{
Apos = value.indexof ("@")
dotpos = value.lastindexof (".")
If (APOS <1 || DOTPOS-APOS <2)
{Alert (Alerttxt); Return false}
else {Return True}
}
}
Function value_form (thisform)
{{
with (thisform)
{{
If (Validate_email (Email, "Not a Valid E-Mail address!" == False)
{email.focus (); Return false}
}
}
</script>
</head>
<body>
<form action = "submitPage.htm" onsubmit = "Return value_form (this);" Method = "Post">>
Email: <input type = "text" name = "email" size = "30">
<input type = "submit" value = "submit">
</form>
</body>
</html>