Advertisement
MertcanGokgoz

validate js

Dec 30th, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //--Validation
  2. function validatePositiveDecimalsOnly(e) {
  3.     if (e.keyCode != 46 && e.keyCode > 31
  4.       && (e.keyCode < 48 || e.keyCode > 57))
  5.         return false;
  6. }
  7.  
  8. function validateNumbersOnly(e) {
  9.     if ((e.keyCode < 48) || (e.keyCode > 57)) {
  10.         return false;
  11.     }
  12. }
  13.  
  14. function validatePhoneNumber(e) {
  15.     if ((e.keyCode < 48) || (e.keyCode > 57)) {
  16.         if ((e.keyCode != 40) && (e.keyCode != 41) && (e.keyCode != 45))
  17.             return false;
  18.     }
  19. }
  20.  
  21. function validateEmail(email) {
  22.     var emailFormat = email.slice(email.indexOf('@'), email.length);
  23.     if (email.indexOf('@') == -1 || emailFormat.indexOf('.') == -1) {
  24.         if (email.length !== 0) {
  25.             return false;
  26.         }
  27.         else {
  28.             return true;
  29.         }
  30.     }
  31.     else {
  32.         return true;
  33.     }
  34. }
  35.  
  36. function isNumeric(val) {
  37.     var numeric = true;
  38.     var chars = "0123456789";
  39.     var len = val.length;
  40.     var char = "";
  41.     for (i = 0; i < len; i++) {
  42.         char = val.charAt(i);
  43.         if (chars.indexOf(char) == -1) {
  44.             numeric = false;
  45.         }
  46.     }
  47.     return numeric;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement