php特殊字符过滤综合例子

php中文网
发布: 2016-07-25 08:54:01
原创
1278人浏览过
  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特殊字符处理函数的例子



PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号