JS verification form)

Source: Internet
Author: User

1. length limit
<SCRIPT>
Function Test ()
{
If (document. A. B. value. length> 50)
{
Alert ("cannot exceed 50 characters! ");
Document. A. B. Focus ();
Return false;
}
}
</SCRIPT>
<Form name = A onsubmit = "return test ()">
<Textarea name = "B" Cols = "40" Wrap = "virtual" rows = "6"> </textarea>
<Input type = "Submit" name = "Submit" value = "check">
</Form>

2. Only Chinese characters are allowed
<Input onkeyup = "value ="/oblog/value. Replace (/[^/u4e00-/u9fa5]/g, '')">

3. "English only
<Script language = JavaScript>
Function onlyeng ()
{
If (! (Event. keycode> = 65 & event. keycode <= 90 ))
Event. returnvalue = false;
}
</SCRIPT>

<Input onkeydown = "onlyeng ();">

4. Only numbers are allowed.
<Script language = JavaScript>
Function onlynum ()
{
If (! (Event. keycode> = 48 & event. keycode <= 57) | (event. keycode> = 96 & event. keycode <= 105 )))
// Consider the numeric keys on the keypad
Event. returnvalue = false;
}
</SCRIPT>

<Input onkeydown = "onlynum ();">

5. Only English characters and numbers are allowed.
<Input onkeyup = "value ="/oblog/value. replace (/[/W]/g, "'') "onbeforepaste =" clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^/d]/g, '')">

6. Verify the fuel tank format
<Script language = JavaScript runat = Server>
Function isemail (stremail ){
If (stremail. search (/^/W + (-/W +) | (/. /W +) */@ [A-Za-z0-9] + ((/. |-) [A-Za-z0-9] + )*/. [A-Za-z0-9] + $ /)! =-1)
Return true;
Else
Alert ("oh ");
}
</SCRIPT>
<Input type = text onblur = isemail (this. Value)>

7. Shielding keywords (here, shielding ***** and ****)
<Script language = "javascript1.2">
Function Test (){
If (. b. value. indexof ("***") = 0) | (. b. value. indexof ("***") = 0 )){
Alert (":)");
A. B. Focus ();
Return false ;}
}
</SCRIPT>
<Form name = A onsubmit = "return test ()">
<Input type = text name = B>
<Input type = "Submit" name = "Submit" value = "check">
</Form>

8. Whether the two passwords are the same
<Form method = post action = "">
<Input type = "password" id = "input1">
<Input type = "password" id = "input2">
<Input type = "button" value = "test" onclick = "check ()">
</Form>
<SCRIPT>
Function check ()
{
With (document. All ){
If (input1.value! = Input2.value)
{
Alert ("false ")
Input1.value = "";
Input2.value = "";
}
Else document. Forms [0]. Submit ();
}
}
</SCRIPT>

Right-click shielding
Oncontextmenu = "Return false" ondragstart = "Return false" onselectstart = "Return false"
Add to Body

 

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.