Advertisement
Guest User

Untitled

a guest
May 25th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. /* Form Validation
  2. * For mobile devices and Ipad
  3. * Or any device which doesn't support HTML5 form validation
  4. */
  5.  
  6. /* Email Validation */
  7.  
  8. function ValidateEmail(email) {
  9. var expr = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
  10. return expr.test(email);
  11. };
  12.  
  13.  
  14.  
  15. $(document).ready(function(){
  16.  
  17. $("#SMS_PhoneNumber").keydown(function (e) {
  18. if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
  19. (e.keyCode == 65 && ( e.ctrlKey === true || e.metaKey === true ) ) ||
  20. (e.keyCode >= 35 && e.keyCode <= 40)) {
  21. return;
  22. }
  23. if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
  24. e.preventDefault();
  25. }
  26. });
  27.  
  28. $('#firstname').bind('keyup blur',function(){
  29. var node = $(this);
  30. node.val(node.val().replace(/[^a-zA-Z]/g,'') ); }
  31. );
  32.  
  33.  
  34.  
  35. $("#SMS_PhoneNumber").change(function () {
  36. var mobile = $(this).val();
  37. if (mobile.length <= 9) {
  38. $(this).addClass("inputerror");
  39. } else if (mobile.length > 9) {
  40. $(this).removeClass("inputerror");
  41. }
  42. });
  43.  
  44.  
  45. });
  46.  
  47. $(document).on("keyup", "input.inputerror", function(){
  48. $(this).removeClass("inputerror");
  49. });
  50.  
  51. $(document).on("keyup", "#firstname", function(){
  52. $('#firstname').attr('placeholder', 'First Name').removeClass('placeholder-error');
  53. });
  54.  
  55. $(document).on("keyup", "#email", function(){
  56. $('#email').attr('placeholder', 'Email').removeClass('placeholder-error');
  57. });
  58.  
  59.  
  60. var form = document.getElementById('form');
  61. form.noValidate = true;
  62. form.addEventListener('submit', function(event) {
  63. if (!event.target.checkValidity()) {
  64. event.preventDefault();
  65. var firstname = $('#firstname').val();
  66. var email = $('#email').val();
  67. if(firstname === ''){
  68. $('#firstname').addClass("inputerror");
  69. $('#firstname').attr('placeholder', 'First name is required').addClass('placeholder-error');
  70. }
  71. if(email === ''){
  72. $('#email').addClass("inputerror");
  73. $('#email').attr('placeholder', 'Email is required').addClass('placeholder-error');
  74. }
  75.  
  76. if (!ValidateEmail($("#email").val())) {
  77. $('#email').addClass("inputerror");
  78. e.preventDefault();
  79. }
  80. }
  81.  
  82. }, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement