Virajsinh

JavaScript Validation

Dec 19th, 2019
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Space Allowed Only
  2. function ValidateAlpha(evt)
  3. {
  4.     var keyCode = (evt.which) ? evt.which : evt.keyCode
  5.     if ((keyCode < 65 || keyCode > 90) && (keyCode < 97 || keyCode > 122) && keyCode != 32)
  6.      
  7.     return false;
  8.         return true;
  9. }
  10. // "&& keyCode != 32" Remove this to Space not Allowed.
  11. //call function : onkeypress="return ValidateAlpha(event);"
  12.  
  13. //Numeric Value allow only
  14. function isNumberKey(evt){
  15.     var charCode = (evt.which) ? evt.which : evt.keyCode
  16.     if (charCode != 46 && charCode > 31
  17.         && (charCode < 48 || charCode > 57))
  18.         return false;
  19.     return true;
  20. }
  21.  
  22. //call function : onkeypress="return isNumberKey(event)"
  23.  
  24. //Mobile Validation
  25.  
  26. $('.NumOnly').on('input', function (event) {
  27. this.value = this.value.replace(/[^0-9]/g, '');
  28. });
  29.  
  30. $('.NumDotOnly').on('input', function (event) {
  31. this.value = this.value.replace(/[^0-9.]/g, '');
  32. });
  33.  
  34. $(".AlphaDotOnly").on("input", function (event) {
  35. this.value = this.value.replace(/[^a-zA-Z .]/g, '');
  36. });
  37.  
  38. $(".AlphaOnly").on("input", function (event) {
  39. this.value = this.value.replace(/[^a-zA-Z]/g, '');
  40. });
  41.  
  42. function numberMobile(e){
  43.     e.target.value = e.target.value.replace(/[^\d]/g,'');
  44.     return false;
  45. }
  46.  
  47. function AlphaOnly(e){
  48.     e.target.value = e.target.value.replace(/[^a-zA-Z]/g, '');
  49.     return false;
  50. }
  51.  
  52. $(".modal").on("hidden.bs.modal", function(){
  53.     $('#frm_newsletter')[0].reset(); //input control reset
  54.     $("#frm_newsletter").validate().resetForm(); // validation error reset
  55. });
Add Comment
Please, Sign In to add comment