Jquery.validate combined with Poshytip for perfect verification of forms

Source: Internet
Author: User

1. js that needs to be referenced
  1. <script src="/themes/default/lib/jquery/jquery-1.7.1.min.js" type="Text/javascript" ></script >
  2. <!--Bubbles Tips-
    <script src= "/themes/default/lib/poshytip/jquery.poshytip.min.js" type= "Text/javascript" ></script>
    <link href= "/themes/default/lib/poshytip/tip-yellow/tip-yellow.css" rel= "stylesheet"
    Type= "Text/css"/>

  3. <!--public functions--
  4. <script src="/themes/default/lib/function.js" type="Text/javascript" ></script>
  5. function.js Code:
  6. //============================================
  7. formtip===================================
  8. (function ($) {
  9. $.fn.formtip = function (message, second, option) {
  10. if (second = = undefined)
  11. second = 3;
  12. $ (". Tip-yellow"). Remove ();
  13. try {
  14. $ (this). Poshytip ({className: ' Tip-yellow ', content:message, Timeonscreen:second *, Showon: ' None ', Alignto: ' t  Arget ', Alignx: ' Inner-left ', offsetx:0, Offsety:5}). Poshytip ("show");
  15. $ (this). focus (); //Note that to combine jquery.validate must be placed in the back
  16. } catch (e) {
  17. $ (this). blur (function () {
  18. alert (message);
  19. });
  20. }
  21. }
  22. }) (JQuery);
  23. //====================================
  24. <!--form validation, you need to add class="required" to the field
  25. <script src="/themes/default/lib/validate/jquery.validate.min.js" type="Text/javascript" ></ Script>
  26. <script src="/themes/default/lib/validate/messages_cn.js" type="Text/javascript" ></script>
  27. <script src="/themes/default/lib/validate/jquery.validate.extend.js" type="Text/javascript" ></ Script>
2. Page usage
  1. //form validation
  2. $ ("#form_customer"). Validate ({
  3. Rules: {
  4. Cus_name: {
  5. Rangelength: [2, 20]
  6. },
  7. Cus_tel: {
  8. Remote: {
  9. URL: '/apps/crm/loaddata/validatephone/'
  10. //, data: {
  11. //Action:function () {return "Validate_phone";}
  12. //                    }  
  13. },
  14. Con_name: {
  15. Rangelength: [2, 20]
  16. }
  17. }
  18. },
  19. Messages: {
  20. Cus_name: {
  21. Required: "Customer name cannot be empty!" ",  
  22. Rangelength: "Customer name length must be between 2-20"
  23. },
  24. Cus_tel: {
  25. Remote: "The phone or mobile number already exists!" " 
  26. },
  27. Con_name: {
  28. Required: "The primary contact name cannot be empty!" ",  
  29. Rangelength: "Primary Contact name length must be between 2-20"
  30. }
  31. },
  32. Success:function (Element) {
  33. var elem = $ (element);
  34. Elem.poshytip (' Disable ');
  35. Elem.poshytip (' Destroy ');
  36. //        },
  37. Errorplacement: function (Error, Element) {
  38. var errormsg = error[0].innerhtml;
  39. var elementname = element[0].name;
  40. $ ("#" + elementname). Formtip (ERRORMSG);
  41. }
  42. });
3. Demo

If you have any questions, can give me a message , I will take time to answer.

I Weibo: @LeaveBugsAway welcome nagging.

Jquery.validate combined with Poshytip for perfect verification of forms

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.