Home > Web Front-end > JS Tutorial > body text

Example of using javascript form verification (javascript verification email)

PHPz
Release: 2018-09-30 16:36:14
Original
1762 people have browsed it

JavaScript can be used to validate input data in HTML forms before the data is sent to the server.

Typical form data validated by JavaScript are:

Has the user filled in the required fields in the form?
Is the email address entered by the user legal?
Has the user entered a valid date?
Did the user enter text in the numeric field?

Required (or required) items

The following function is used to check whether the user has filled in the required (or required) items in the form. If the required field or the required field is empty, the warning box will pop up and the return value of the function is false, otherwise the return value of the function is true (meaning there is no problem with the data):

function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {alert(alerttxt);return false}
else {return true}
}
}
Copy after login

E-mail verification (verify email address)

The following function checks whether the entered data conforms to the basic syntax of the email address.

It means that the input data must contain the @ symbol and the period (.). At the same time, @ cannot be the first character of the email address, and there must be at least one period after @:

function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@")
dotpos=value.lastIndexOf(".")
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false}
else {return true}
}
}
Copy after login

Example:






Email:
Copy after login

The above is the entire content of this chapter, and more For more related tutorials, please visit JavaScript Video Tutorial!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template