基本注册表单验证

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基本注册表单验证相关的知识,希望对你有一定的参考价值。

I came across this little snippet... and thought it was rather nice.
  1. <SCRIPT LANGUAGE="javascript">
  2. function validate(form) {var e = form.elements, m = '';
  3. if(!e['firstname'].value) {m += '- First name is required. ';}
  4. if(!e['lastname'].value) {m += '- Last name is required. ';}
  5. if(!e['address'].value) {m += '- Address is required. ';}
  6. if(!e['city'].value) {m += '- City is required. ';}
  7. if(!e['postcode'].value) {m += '- Postcode is required. ';}
  8. if(!e['telephone'].value) {m += '- Telephone number is required. ';}
  9. if(!/.[email protected][^.]+(.[^.]+)+/.test(e['email'].value)) {
  10. m += '- E-mail requires a valid e-mail address. ';
  11. }
  12. if(!e['username'].value) {m += '- Username is required. ';}
  13. if(!e['password'].value) {m += '- Password is required. ';}
  14. if(e['password'].value != e['confirm'].value) {
  15. m += '- Your password and confirmation password do not match. ';
  16. }
  17. if(m) {
  18. alert('The following error(s) occurred: ' + m);
  19. return false;
  20. }
  21. return true;
  22. }
  23. </SCRIPT>

以上是关于基本注册表单验证的主要内容,如果未能解决你的问题,请参考以下文章

php中的注册表单验证

无法获得 jquery 表单验证来注册 $.post 元素

注册全局指令(表单验证)

注册表单无刷新验证+php无刷新刷新验证码

Thinkphp框架 表单自动验证登录注册 ajax自动验证登录注册

Flask WTForm 未验证,未报告表单错误