PHP special Character Filtering comprehensive example

Source: Internet
Author: User
Tags php form php form submit
  1. Special characters for filtering strings
  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 ("User name 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 problem cannot be empty!") ");
  31. return false;
  32. }
  33. if (answer = = "") {
  34. Alert ("The password question answer 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 ("User name contains illegal characters, please do not use special characters!") ");
  48. return false;
  49. }
  50. if (Username.length > | | username.length < 3) {
  51. Alert ("User name length does not meet the requirements" 3-28 characters "username.length");
  52. return false;
  53. }
  54. if (passwd! = passwd2) {
  55. Alert ("Two input passwords are inconsistent!");
  56. return false;
  57. }
  58. if (Passwd.length > | | passwd.length < 5) {
  59. Alert ("The password length does not meet the requirement" 5-28 characters "");
  60. return false;
  61. }
  62. if (Checkdata.test (realname)) {
  63. Alert ("real name contains illegal characters, please do not use special characters!") ");
  64. return false;
  65. }
  66. if (Realname.length > | | realname.length < 3) {
  67. Alert ("The true name length does not meet the requirement" 3-28 characters "");
  68. return false;
  69. }
  70. if (Question.length > 98 | | question.length < 3) {
  71. Alert ("The password hint 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 question answer length does not meet the requirement" 3-98 characters "");
  76. return false;
  77. }//Scripting 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 > | | email.length < 5) {
  83. Alert ("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 contact address length does not meet the requirement" within 48 characters ");
  92. return false;
  93. }
  94. if (checkphone.test (phone)) {
  95. Alert ("The contact number contains illegal characters! ");
  96. return false;
  97. }
  98. if (Address! = "" && (Phone.length > 18 | | Phone.length < 7)) {
  99. Alert ("Contact phone length does not meet the requirement" 7-18 characters "");
  100. return false;
  101. }
  102. }
Copy Code

PHP Filter Special characters utility function php form Submit special character filter method HTML special character filter PHP class URL link special character escape method php special character escape detailed PHP filter parameters special characters anti-injection PHP Methods for filtering illegal and special strings examples of PHP special character handling functions

  • Related Article

    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.