php特殊字符过滤综合例子

原创
2016-07-25 08:54:01 625浏览
  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 < 3 ) {
  51. alert("用户名长度不符合要求【3-28个字符】 username.length");
  52. return false;
  53. }
  54. if ( passwd != passwd2 ) {
  55. alert("两次输入的密码不一致!");
  56. return false;
  57. }
  58. if ( passwd.length > 28 || passwd.length < 5 ) {
  59. alert("密码长度不符合要求【5-28个字符】");
  60. return false;
  61. }
  62. if ( checkdata.test(realname) ) {
  63. alert("真实姓名包含非法字符,请不要使用特殊字符!");
  64. return false;
  65. }
  66. if ( realname.length > 28 || realname.length < 3 ) {
  67. alert("真实姓名长度不符合要求【3-28个字符】");
  68. return false;
  69. }
  70. if ( question.length > 98 || question.length < 3 ) {
  71. alert("密码提示问题长度不符合要求【6-98个字符】");
  72. return false;
  73. }
  74. if ( answer.length > 98 || answer.length < 3 ) {
  75. alert("问题答案长度不符合要求【3-98个字符】");
  76. return false;
  77. } //脚本学堂 http://bbs.it-home.org
  78. if ( ! checkmail.test(email) ) {
  79. alert("e-mail包含非法字符!");
  80. return false;
  81. }
  82. if ( email.length > 48 || email.length < 5 ) {
  83. alert("e-mail长度不符合要求【5-48个字符】");
  84. return false;
  85. }
  86. if ( checkdata.test(address) ) {
  87. alert("联系地址包含非法字符!");
  88. return false;
  89. }
  90. if ( address != "" && address.length > 48 ) {
  91. alert("联系地址长度不符合要求【48个字符以内】");
  92. return false;
  93. }
  94. if ( checkphone.test(phone) ) {
  95. alert("联系电话包含非法字符!");
  96. return false;
  97. }
  98. if ( address != "" && ( phone.length > 18 || phone.length < 7 ) ) {
  99. alert("联系电话长度不符合要求【7-18个字符】");
  100. return false;
  101. }
  102. }
复制代码

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



声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
上一条:php字符串查找函数(strrpos与strchr) 下一条:php过滤特殊字符实用函数

相关文章

查看更多