PHP jQuery表單,帶驗證_PHP教程

來源:互聯網
上載者:User

PHP jQuery表單,帶驗證

Email檢測,密碼重複資料偵測,可以用於表單發送的各種環境,例如發送反饋,註冊帳號

示範

XML/HTML Code
    • Invalid Name: We want names with more than 3 letters!
    • Invalid E-mail: Stop cowboy! Type a valid e-mail please :P
    • Passwords are invalid: Passwords doesn't match or are invalid!
    • Ivalid message: Type a message with at least with 10 letters
    • Congratulations! All fields are OK ;)
  1. validation.php

    PHP Code
    1. function validateName($name){
    2. //if it's NOT valid
    3. if(strlen($name) < 4)
    4. return false;
    5. //if it's valid
    6. else
    7. return true;
    8. }
    9. function validateEmail($email){
    10. return ereg(^[a-zA-Z0-9]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$, $email);
    11. }
    12. function validatePasswords($pass1, $pass2) {
    13. //if DOESN'T MATCH
    14. if(strpos($pass1, ' ') !== false)
    15. return false;
    16. //if are valid
    17. return $pass1 == $pass2 && strlen($pass1) > 5;
    18. }
    19. function validateMessage($message){
    20. //if it's NOT valid
    21. if(strlen($message) < 10)
    22. return false;
    23. //if it's valid
    24. else
    25. return true;
    26. }
    27. ?>

http://www.bkjia.com/PHPjc/735890.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/735890.htmlTechArticlePHP jQuery表單,帶驗證 Email檢測,密碼重複資料偵測,可以用於表單發送的各種環境,例如發送反饋,註冊帳號 示範 XML/HTML Code Invalid Name: We want nam...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.