1

我希望我的代码更准确。有人可以建议我编写以下更合适的代码片段吗?

<script>

var frmvalidator  = new Validator("SubscriptionForm");
 frmvalidator.EnableOnPageErrorDisplaySingleBox();
 frmvalidator.EnableMsgsTogether();

  frmvalidator.addValidation("usernameReg","req","Please enter your Username");
  frmvalidator.addValidation("usernameReg","maxlen=20", "Max length for Username is 20");
  frmvalidator.addValidation("usernameReg","alpha_s","Username can contain alphabetic chars only");

  frmvalidator.addValidation("usernameReg","req","Please enter your Username");
  frmvalidator.addValidation("usernameReg","maxlen=20", "Max length for Username is 20");
  frmvalidator.addValidation("usernameReg","alpha_s","Username can contain alphabetic chars only");
  frmvalidator.addValidation("fname","req","Please enter your First Name");
  frmvalidator.addValidation("fname","maxlen=20",   "Max length for FirstName is 20");
  frmvalidator.addValidation("fname","alpha_s","Name can contain alphabetic chars only");


  frmvalidator.addValidation("lname","req","Please enter your Last Name");
  frmvalidator.addValidation("lname","maxlen=20","For LastName, Max length is 20");

  frmvalidator.addValidation("email","maxlen=50");
  frmvalidator.addValidation("email","req");
  frmvalidator.addValidation("email","email");

</script>
4

1 回答 1

0

@Nida Hafeez,

如果您愿意在下一个项目中开始使用 jquery,这将对您有很大帮助:http: //www.w3schools.com/jquery/default.asp

还有一个来自 jQuery 的很好的表单验证器

http://docs.jquery.com/Plugins/Validation

于 2012-10-22T11:21:37.033 回答