Home  >  Article  >  Backend Development  >  Comprehensive example of php special character filtering

Comprehensive example of php special character filtering

WBOY
WBOYOriginal
2016-07-25 08:54:01922browse
  1. //Filter special characters of string
  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("Username cannot be empty!");
  19. return false;
  20. }
  21. if ( passwd == "" ) {
  22. alert("Password cannot be empty!");
  23. return false;
  24. }
  25. if ( realname == "" ) {
  26. alert("Real name cannot be empty!");
  27. return false;
  28. }
  29. if ( question == "" ) {
  30. alert("Password question cannot be empty!" ");
  31. return false;
  32. }
  33. if ( answer == "" ) {
  34. alert("The answer to the password question cannot be empty!");
  35. return false;
  36. }
  37. if ( email == "" ) {
  38. alert("e-mail cannot be empty!");
  39. return false;
  40. }
  41. if ( checkusername.test(username) ) {
  42. }else{
  43. alert("Username cannot be all numbers!");
  44. return false;
  45. }
  46. if ( checkdata.test(username) ) {
  47. alert("The username contains illegal characters, please do not use special characters!");
  48. return false;
  49. }
  50. if ( username.length > 28 || username.length < 3 ) {
  51. alert("The username length does not meet the requirements [3-28 characters] username.length");
  52. return false;
  53. }
  54. if ( passwd != passwd2 ) {
  55. alert ("The passwords entered twice are inconsistent!");
  56. return false;
  57. }
  58. if ( passwd.length > 28 || passwd.length < 5 ) {
  59. alert("The password length does not meet the requirements [5-28 characters]");
  60. return false;
  61. }
  62. if ( checkdata.test(realname) ) {
  63. alert("The real name contains illegal characters, please do not use special characters!");
  64. return false;
  65. }
  66. if ( realname.length > 28 || realname.length < 3 ) {
  67. alert("The length of the real name does not meet the requirements [3-28 characters]");
  68. return false;
  69. }
  70. if ( question.length > ; 98 || question.length < 3 ) {
  71. alert("The password question length does not meet the requirements [6-98 characters]");
  72. return false;
  73. }
  74. if ( answer.length > 98 || answer.length < 3 ) {
  75. alert("The answer length does not meet the requirements [3-98 characters]");
  76. return false;
  77. } //Script Academy http://bbs.it-home.org
  78. if ( ! checkmail.test(email) ) {
  79. alert("e-mail contains illegal characters!");
  80. return false;
  81. }
  82. if ( email.length > 48 || email.length < 5 ) {
  83. alert("The e-mail length does not meet the requirements [5-48 characters]");
  84. return false;
  85. }
  86. if ( checkdata.test(address) ) {
  87. alert("The contact address contains illegal characters! ");
  88. return false;
  89. }
  90. if ( address != "" && address.length > 48 ) {
  91. alert("The length of the contact address does not meet the requirements [within 48 characters]");
  92. return false;
  93. }
  94. if ( checkphone.test(phone) ) {
  95. alert("Contact number contains illegal characters!");
  96. return false;
  97. }
  98. if ( address != "" && ( phone.length > 18 || phone .length < 7 ) ) {
  99. alert("The length of the contact number does not meet the requirements [7-18 characters]");
  100. return false;
  101. }
  102. }
Copy code

PHP utility function for filtering special characters Special character filtering method for php form submission html special character filter php class How to escape special characters in url links Detailed explanation of php special character escaping php filter parameter special characters anti-injection php method to filter illegal and special strings Examples of php special character processing functions



Statement:
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 admin@php.cn