各种常用注册页面表单验证
这里介绍的第一个是最原始的表单验证方式,即没有使用即时验证,需要点击提交按钮才进行验证,也没有使用正则表达式或者AJAX验证,也或者是JQuery的验证,不过这么多验证方式接着第一个后面都会写出来的
1、最原始的注册验证方式,需要通过点击提交按钮才验证
先上图

具体代码
Html代码
- <span style="font-size: medium;"><span style="font-size: large;"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>无标题文档</title>
- </head>
- <body>
- <div id="content">
- <!--首页的中间部分-->
- <SCRIPT language="javascript" type="text/javascript">
- //checkUserName() && sNameCheck() && passCheck() && bdaycheck() && genderCheck() && emailcheck() &&
- function validateform(){
- if(checkUserName() && sNameCheck() && passCheck()&& emailcheck() && bdaycheck() && genderCheck() && agree( ))
- return true;
- else
- return false;
- }
- //validate Name
- function checkUserName(){
- var fname = document.userfrm.fname.value;
- var lname = document.userfrm.lname.value;
- // validate first Name
- if(fname.length != 0){
- for(i=0;i<fname.length;i++){
- var ftext = fname.substring(i,i+1);
- if(ftext < 9 || ftext > 0){
- alert("名字中包含数字 "+"请删除名字中的数字和特殊字符");
- document.userfrm.fname.focus();
- document.userfrm.fname.select();
- return false
- }
- }
- }
- else{
- alert("请输入“名字”文本框");
- document.userfrm.fname.focus();
- return false
- }
- // Validate last name
- if(fname.length != 0){
- for(i=0;i<fname.length;i++){
- var ftext = fname.substring(i,i+1);
- if(ftext < 9 || ftext > 0){
- alert("名字中包含数字 "+"请删除名字中的数字和特殊字符");
- document.userfrm.fname.focus();
- document.userfrm.fname.select();
- return false
- }
- }
- }
- else{
- alert("请输入“名字”文本框");
- document.userfrm.fname.focus();
- return false
- }
- // Validate last name
- if(lname.length != 0){
- for(j=0;j<lname.length;j++){
- var ltext = lname.substring(j,j+1);
- if(ltext < 9 || ltext > 0){
- alert("姓氏中包含数字 "+"请删除姓氏中的数字和特殊字符");
- document.userfrm.lname.focus();
- document.userfrm.lname.select();
- return false
- }
- }
- }
- else{
- alert("“姓氏”文本框为空");
- document.userfrm.lname.focus();
- return false;
- }
- return true;
- }
- // Login Name Validation
- function sNameCheck(){
- var sname = document.userfrm.sname.value;
- var illegalChars = /W/;
- if(sname.length != 0){
- if(illegalChars.test(sname)){
- alert("登录名无效");
- document.userfrm.sname.select();
- return false;
- }
- }
- else{
- alert("是否忘记输入登录名?");
- document.userfrm.sname.focus();
- return false
- }
- return true;
- }
- //Validate password
- function passCheck(){
- var userpass = document.userfrm.pass.value;
- var ruserpass = document.userfrm.rpass.value;
- var illegalChars = /[W_]/;// allow only charactors and numbers
- // Check if Password field is blank.
- if(userpass == "" || ruserpass == ""){
- alert("未输入密码 " + "请输入密码");
- document.userfrm.pass.focus();
- return false;
- }
- // Check if password length is less than 6 charactor.
- if(userpass.length < 6){
- alert("密码必须多于或等于 6 个字符。 ");
- document.userfrm.pass.focus();
- return false;
- }
- //check if password contain illigal charactors.
- else if(illegalChars.test(userpass)){
- alert("密码包含非法字符");
- document.userfrm.pass.select();
- return false;
- }
- else if(userpass != ruserpass){
- alert("密码不符");
- document.userfrm.rpass.select();
- return false;
- }
- return true;
- }
- // Email Validation
- function emailcheck(){
- var usermail = document.userfrm.email.value;
- if(usermail.length == "0"){
- alert("Email 文本框为空")
- document.userfrm.email.focus();
- return false;
- }
- if( usermail.indexOf("@") < 0 || usermail.indexOf(".") < 0 || usermail.indexOf("@") > usermail.indexOf(".")){
- alert("Email 地址无效");
- return false;
- }
- return true;
- }
- function bdaycheck(){
- var bmonth = document.userfrm.bmon.value;
- var bday = document.userfrm.bday.value;
- var byear = document.userfrm.byear.value;
- //alert(bmonth + "/" + bday + "/" + byear);
- if(bmonth == "" || bday == "" || byear == "" || bday=="dd" || byear == "yyyy"){
- alert("请输入您的生日");
- document.userfrm.bmon.focus();
- return false;
- }
- for(i=0; i<bday.length; i++){
- var bnum = bday.substring(i,i+1)
- if(!(bnum < 9 || bnum > 0)){
- alert("生日无效");
- document.userfrm.bday.focus();
- return false;
- }
- }
- for(j=0; j<byear.length; j++){
- var bynum = byear.substring(j,j+1)
- if(!(bynum < 9 || bynum > 0)){
- alert("生日无效");
- document.userfrm.byear.focus();
- return false;
- }
- }
- &n
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇: C#模拟http 发送post或get请求
