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=java script ﹥ function onlyEng() { if(!(event.keyCode﹥=65&&event.keyCode﹤=90)) event.returnvalue=false; } ﹤/ script ﹥﹤input onkeydown="onlyEng();"﹥ |
4. Only numbers are allowed:
<Script language = java script> 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 email format:
﹤ script LANGUAGE=java script 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="java script 1.2"﹥ function test() { if((a.b.value.indexOf ("***") == 0)||(a.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 ﹥ |
- How to dynamically change the image size through JavaScript
- Comprehensive list of practical JavaScript development tools
- Programming Language ranking in June: JavaScript is just getting started
- The essence of JavaScript Language