avatar
force user enter date of birth Javascript
this.$dob = $(this.$elements.dob);
this.$dob.on('input', this.myHandler);

private myHandler = (): void => {
  const dob = this.$dob.val() as string;
  const dobRegex = new RegExp('^[0-9/]*$');

  if (dob.length > 0) {
    const c = dob.substr(-1);
    if (dobRegex.test(c)) {
      this.$dob.val(dob);
    } else {
      this.$dob.val(dob.slice(0, -1));
    }
  }
}
24
force user enter only digit jquery
You need to login to do this manipulation!