Php special character filtering example

Source: Internet
Author: User
Tags php form
Php special character filtering example

  1. // Filter special characters of a 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 ("the user name cannot be blank! ");
  19. Return false;
  20. }
  21. If (passwd = ""){
  22. Alert ("The password cannot be blank! ");
  23. Return false;
  24. }
  25. If (realname = ""){
  26. Alert ("real name cannot be blank! ");
  27. Return false;
  28. }
  29. If (question = ""){
  30. Alert ("password issue cannot be blank! ");
  31. Return false;
  32. }
  33. If (answer = ""){
  34. Alert ("The answer to the password cannot be blank! ");
  35. Return false;
  36. }
  37. If (email = ""){
  38. Alert ("e-mail cannot be blank! ");
  39. Return false;
  40. }
  41. If (checkusername. test (username )){
  42. } Else {
  43. Alert ("the user name cannot be all numbers! ");
  44. Return false;
  45. }
  46. If (checkdata. test (username )){
  47. Alert ("the user name contains invalid characters. please do not use special characters! ");
  48. Return false;
  49. }
  50. If (username. length> 28 | username. length <3 ){
  51. Alert ("invalid username length [3-28 characters] username. length ");
  52. Return false;
  53. }
  54. If (passwd! = Passwd2 ){
  55. Alert ("The two passwords are inconsistent! ");
  56. Return false;
  57. }
  58. If (passwd. length> 28 | passwd. length <5 ){
  59. Alert ("invalid password length [5-28 characters ]");
  60. Return false;
  61. }
  62. If (checkdata. test (realname )){
  63. Alert ("The real name contains invalid characters. please do not use special characters! ");
  64. Return false;
  65. }
  66. If (realname. length> 28 | realname. length <3 ){
  67. Alert ("invalid real name length [3-28 characters ]");
  68. Return false;
  69. }
  70. If (question. length> 98 | question. length <3 ){
  71. Alert ("invalid password prompt length [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 School http://bbs.it-home.org
  78. If (! Checkmail. test (email )){
  79. Alert ("e-mail contains invalid characters! ");
  80. Return false;
  81. }
  82. If (email. length> 48 | email. length <5 ){
  83. Alert ("invalid email length [5-48 characters ]");
  84. Return false;
  85. }
  86. If (checkdata. test (address )){
  87. Alert ("the contact address contains invalid characters! ");
  88. Return false;
  89. }
  90. If (address! = "" & Address. length> 48 ){
  91. Alert ("invalid contact address length [less than 48 characters ]");
  92. Return false;
  93. }
  94. If (checkphone. test (phone )){
  95. Alert ("The contact number contains invalid characters! ");
  96. Return false;
  97. }
  98. If (address! = "" & (Phone. length> 18 | phone. length <7 )){
  99. Alert ("invalid contact phone number [7-18 characters ]");
  100. Return false;
  101. }
  102. }

Php filter special character utility functions php form submission special character filtering methods html special character filtering special character escaping methods in php url links php special character escaping explanation php filter parameters special characters anti-injection php filter an example of php special character processing function for illegal methods with special strings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.