>  기사  >  백엔드 개발  >  php特殊字符过滤综合例子

php特殊字符过滤综合例子

WBOY
WBOY원래의
2016-07-25 08:54:01920검색
  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特殊字符处理函数的例子



성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.