jQuery Validation Store

by Faisal Khan Janjua

JavaScript

// Validations Start
$(document).on('keypress', '.numbersOnly', function (e) {
	if(e.key=='e'||e.key=='E'||e.key=='+'||e.key=='-'){
		return false;
	}
	if(!$(this).hasClass('allowDecimals')){
		if(e.key=='.'){
			return false;
		}
	}
});
$(document).on('input', '.numbersOnly', function () {
  this.value = this.value.replace(/[^0-9]+/g, '');
});
$(document).on('mouseenter paste', '.numbersOnly', function () { // Prevent Paste & Drag
  var val = $(this).val();
  if (val != '0') {
    val = val.replace(/[^0-9]+/g, "");
    $(this).val(val);
  }
});
$(document).on('input', '.alphabetsOnly', function () {
  this.value = this.value.replace(/[^A-Za-z ]/g, '');
});
$(document).on('mouseenter paste', '.alphabetsOnly', function () { // Prevent Paste & Drag
  var val = $(this).val();
  if (val != '0') {
    val = val.replace(/[^A-Za-z ]+/g, "");
    $(this).val(val);
  }
});
$(document).on('input', '.alphanumeric', function () {
  this.value = this.value.replace(/[^A-Za-z0-9 ]/g, '');
});
$(document).on('mouseenter paste', '.alphanumeric', function () { // Prevent Paste & Drag
  var val = $(this).val();
  if (val != '0') {
    val = val.replace(/[^A-Za-z0-9 ]+/g, "");
    $(this).val(val);
  }
});
$(document).on("keypress", ".allowDecimals", function (evt) {
  evt = (evt) ? evt : window.event;
  var charCode = (evt.which) ? evt.which : evt.keyCode;
  if (charCode == 8 || charCode == 37) {
    return true;
  } else if (charCode == 46 && $(this).val().indexOf('.') != -1) {
    return false;
  } else if (charCode > 31 && charCode != 46 && (charCode < 48 || charCode > 57)) {
    return false;
  }
  return true;
});
$(document).on("blur mouseenter paste", ".allowDecimals", function () {
  var val = $(this).val();
  if (val != '0') {
    val = val.replace(/[^0-9\.]+/g, "");
    $(this).val(val);
  }
});
$(document).on('input', '.validateEmail', function () {
  this.value = this.value.replace(/[^A-Za-z0-9\.\-_@]/g, '');
});
$(document).on('mouseenter paste', '.validateEmail',...