Alternative usage of Lang and title attributes in input (I don't know if it is feasible)-repost a good article

Source: Internet
Author: User

Find a javascript Form Verification code on the Internet:
Http://blog.yesky.com/Blog/_grace/archive/2005/01/10/62725.html
[Code]
<Input type = "text" Check = "^/d + $" Warning = "the phone number contains invalid characters" name = "Number" value = "">
[/Code]
The check and warning attributes are added to the input file. The form verification function is implemented, but it cannot pass code verification. I thought of using check and warning with Lang, respectively, in this way, the code can be verified, but I don't know if it is feasible?
Will there be any problems in the future?
Please advise.
The modified code is attached.
[HTML]
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"
Http://www.w3.org/TR/html4/loose.dtd>
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> untitled document </title>
<Script language = "JavaScript" type = "text/JavaScript">
//////////////////////////////////////// ////////////////////////////////////////
/*
* --------------- Client form universal verification checkform (oform )-----------------
* Function: verifies all form elements.
* Usage:
* <Form name = "form1" onsubmit = "Return checkform (this)">
* <Input type = "text" name = "ID" Check = "^/S + $" Warning = "ID cannot be blank or contain spaces">
* <Input type = "Submit">
* </Form>
* Author: wanghr100 (Baby gray bean. Net)
* Email: wanghr100@126.com
* Update: 19: 28 2004-8-23
* Note: Be careful when writing regular expressions. Do not let "people with confidence" have loopholes.
* Implemented functions:
* Verify the validity of text, password, hidden, file, textarea, select, radio, and checkbox.
* Function to be implemented: Write the regular expression as a database.
* --------------- Client form universal verification checkform (oform )-----------------
*/
//////////////////////////////////////// ////////////////////////////////////////

// Main Function
Function checkform (oform)
{
VaR els = oform. elements;
// Traverse all Table Elements
For (VAR I = 0; I <els. length; I ++)
{
// Whether verification is required
If (ELS [I]. Lang)
{
// Obtain the verified regular string
VaR sreg = els [I]. Lang;
// Obtain the value of the form, using a common value function
VaR sval = getvalue (ELS [I]);
// String-> regular expression, case insensitive
VaR Reg = new Regexp (sreg, "I ");
If (! Reg. Test (sval ))
{
// If the verification fails, the prompt "warning" appears.
Alert (ELS [I]. Title );
// This form Element gets the focus and uses the universal return Function
Goback (ELS [I])
Return false;
}
}
}
}

// General value functions can be set to three types.
// Text input box. The value is El. value.
// Select one or more items and traverse all options to obtain the number of selected items. The returned result "00" indicates that two items are selected.
// Multiple single drop-down menus, traverse all options to obtain the number of selected results. "0" indicates that one
Function getvalue (EL)
{
// Obtain the type of the form Element
VaR stype = El. type;
Switch (stype)
{
Case "text ":
Case "hidden ":
Case "password ":
Case "file ":
Case "textarea": Return El. value;
Case "checkbox ":
Case "radio": Return getvaluechoose (EL );
Case "select-one ":
Case "select-multiple": Return getvaluesel (EL );
}
// Obtain the selected number of radio and checkbox. "0" is used to represent the selected number. When writing a regular expression, 0 {1,} can be used to represent the selected number.
Function getvaluechoose (EL)
{
VaR svalue = "";
// Retrieve the name of the first element and search for this element group
VaR tmpels = Document. getelementsbyname (El. Name );
For (VAR I = 0; I <tmpels. length; I ++)
{
If (tmpels [I]. Checked)
{
Svalue + = "0 ";
}
}
Return svalue;
}
// Obtain the select number. "0" is used to represent the selected number. When writing a regular expression, we can use 0 {1,} to represent the selected number.
Function getvaluesel (EL)
{
VaR svalue = "";
For (VAR I = 0; I <El. Options. length; I ++)
{
// In the single-choice drop-down box, the prompt option is set to value = ""
If (El. Options [I]. Selected & El. Options [I]. value! = "")
{
Svalue + = "0 ";
}
}
Return svalue;
}
}

// Universal return function, which is used to verify that the returned result is not passed. values can be set to three types.
// Text input box, with the cursor positioned at the end of the text input box
// Select multiple options, and the first option gets the focus
// Multiple single drop-down menus for focus
Function Goback (EL)
{
// Obtain the type of the form Element
VaR stype = El. type;
Switch (stype)
{
Case "text ":
Case "hidden ":
Case "password ":
Case "file ":
Case "textarea": El. Focus (); var RNG = El. createTextRange (); RNG. Collapse (false); RNG. Select ();
Case "checkbox ":
Case "radio": var els = Document. getelementsbyname (El. Name); els [0]. Focus ();
Case "select-one ":
Case "select-multiple": El. Focus ();
}
}
</SCRIPT>
</Head>
<Body>
Test common form functions:
<Form method = "Post" name = "form1" onsubmit = "Return checkform (this)">
Test:
<Input type = "text" name = "test"> not verified <br>
Account: <input type = "text" lang = "^/S + $" Title = "the account cannot be blank, and cannot contain spaces "name =" ID "> cannot be blank <br>
Password: <input type = "password" lang = "/s {6,}" Title = "more than six passwords" name = "ID"> more than six <br>
Tel: <input type = "text" lang = "^/d + $" Title = "the phone number contains invalid characters" name = "Number" value = ""> <br>
Upload a photo: <input type = "file" lang = "(. *)(/. JPG | /. BMP) $ "Title =" the photo should be JPG, BMP format "name =" pic "value =" 1 "> <br>
Date of birth: <input type = "text" lang = "^/d {4}/-/d {} $" Title = "Date Format" name = "DT" value = ""> Date Format: 2004-08-10 <br>
Province:
<Select name = "Sel" lang = "^ 0 $" Title = "select the province">
<Option value = ""> select </option>
<Option value = "1"> Fujian </option>
<Option value = "2"> Hubei Province </option>
</SELECT>
<Br>
Select your favorite sports: <br>
Swimming <input type = "checkbox" name = "C" lang = "^ 0 {2, }$" Title = "Please select 2 or more">
Basketball <input type = "checkbox" name = "C">
Football <input type = "checkbox" name = "C">
Volleyball <input type = "checkbox" name = "C">
<Br>
Your degree:
University <input type = "radio" name = "R" lang = "^ 0 $" Title = "select a degree">
Middle school <input type = "radio" name = "R">
Elementary School <input type = "radio" name = "R">
<Br>
Personal introduction:
<Textarea name = "txts" lang = "^ [/S |/S] {20,} $" Title = "personal description cannot be blank, and no less than 20 words "rows =" 10 "Cols =" 20 "> </textarea> more than 20 words
<Input type = "Submit">
</Form>

</Body>
</Html>

[/Html]

First, let's talk about the feasibility of the main method, but it is best not to use the lang attribute (Lang self-use), which can be appended to the class (such as class = "inputclass A1 A2 ") so that your string does not conflict with the existing class. This will not affect the style of the current element, but also easily use scripts to separate the value you want.

But you are so persistent. Why do you have to pursue code verification?
The so-called wine and meat have passed through, and the Buddha's mind remains. The standard is just a form. I really understand why there is such a standard, so I don't need to care about it.

Each element is an object, and there is nothing wrong with adding custom attributes to these objects. html and XHTML are not allowed. What should we do if all standards are not allowed? Trick: javascript. comrades who swear to follow the standards will do this (especially when using document. Write and innerhtml to output "illegal" Code). In fact, this is all about self-deception! Although it has passed the verification, this idea has seriously deviated from the standard. (in this case, I will write an ASP file. When the request source is w3.org, all standard null documents will be output, and ^ _ ^ will be completely standard at all times ).

Verification is just a means. It doesn't mean that verification is wrong, and the current standards are not perfect. after all, the viewer is looking at your effect, not your code, not the small sign of porn.

PS. Standards are like women. No, but everything follows standards.

 

I have been educated, but sometimes I cannot pass it. I always feel a little uncomfortable. I have already chosen to do it according to the standard. But now I figured it out .:)

 

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.