php特殊字符过滤综合例子

WBOY
Release: 2016-07-25 08:54:01
Original
860 people have browsed it
  1. //过滤字符串的特殊字符
  2. function checkform() {
  3. var username = document.theform.user_name.value;
  4. var realname = document.theform.real_name.value;
  5. var passwd = document.theform.passwd.value;
  6. var passwd2 = document.theform.passwd2.value;
  7. var email = document.theform.email.value;
  8. var question = document.theform.question.value;
  9. var answer = document.theform.answer.value;
  10. var address = document.theform.address.value;
  11. var phone = document.theform.phone.value;
  12. var answer = document.theform.answer.value;
  13. var checkdata = /|'|;|&|#|"|'/;
  14. var checkusername = /[^0-9]/;
  15. var checkmail = /^([a-za-z0-9_-])+@([a-za-z0-9_-])+(.[a-za-z0-9_-])+/;
  16. var checkphone = /[^0-9-]/;
  17. if ( username == "" ) {
  18. alert("用户名不能为空!");
  19. return false;
  20. }
  21. if ( passwd == "" ) {
  22. alert("密码不能为空!");
  23. return false;
  24. }
  25. if ( realname == "" ) {
  26. alert("真实姓名不能为空!");
  27. return false;
  28. }
  29. if ( question == "" ) {
  30. alert("密码问题不能为空!");
  31. return false;
  32. }
  33. if ( answer == "" ) {
  34. alert("密码问题答案不能为空!");
  35. return false;
  36. }
  37. if ( email == "" ) {
  38. alert("e-mail不能为空!");
  39. return false;
  40. }
  41. if ( checkusername.test(username) ) {
  42. }else{
  43. alert("用户名不能全为数字!");
  44. return false;
  45. }
  46. if ( checkdata.test(username) ) {
  47. alert("用户名包含非法字符,请不要使用特殊字符!");
  48. return false;
  49. }
  50. if ( username.length > 28 || username.length alert("用户名长度不符合要求【3-28个字符】 username.length");
  51. return false;
  52. }
  53. if ( passwd != passwd2 ) {
  54. alert("两次输入的密码不一致!");
  55. return false;
  56. }
  57. if ( passwd.length > 28 || passwd.length alert("密码长度不符合要求【5-28个字符】");
  58. return false;
  59. }
  60. if ( checkdata.test(realname) ) {
  61. alert("真实姓名包含非法字符,请不要使用特殊字符!");
  62. return false;
  63. }
  64. if ( realname.length > 28 || realname.length alert("真实姓名长度不符合要求【3-28个字符】");
  65. return false;
  66. }
  67. if ( question.length > 98 || question.length alert("密码提示问题长度不符合要求【6-98个字符】");
  68. return false;
  69. }
  70. if ( answer.length > 98 || answer.length alert("问题答案长度不符合要求【3-98个字符】");
  71. return false;
  72. } //脚本学堂 http://bbs.it-home.org
  73. if ( ! checkmail.test(email) ) {
  74. alert("e-mail包含非法字符!");
  75. return false;
  76. }
  77. if ( email.length > 48 || email.length alert("e-mail长度不符合要求【5-48个字符】");
  78. return false;
  79. }
  80. if ( checkdata.test(address) ) {
  81. alert("联系地址包含非法字符!");
  82. return false;
  83. }
  84. if ( address != "" && address.length > 48 ) {
  85. alert("联系地址长度不符合要求【48个字符以内】");
  86. return false;
  87. }
  88. if ( checkphone.test(phone) ) {
  89. alert("联系电话包含非法字符!");
  90. return false;
  91. }
  92. if ( address != "" && ( phone.length > 18 || phone.length alert("联系电话长度不符合要求【7-18个字符】");
  93. return false;
  94. }
  95. }
复制代码

php过滤特殊字符实用函数 php表单提交特殊字符过滤方法 html特殊字符过滤php类 url链接中特殊字符转义方法 php特殊字符转义详解 php过滤参数特殊字符防注入 php 过滤非法与特殊字符串的方法 php特殊字符处理函数的例子



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!