Link to home
Start Free TrialLog in
Avatar of Lisa B
Lisa B

asked on

Javascript Check User Input

Hi Everyone

I have attached a javascript function that is called onkeyup which should the user enter any characters that are not numbers it will replace this with an empty space.

What I would like to do now is to validate an expiry date entered in the format mm/yy.  So for example the first,second, fourth and fifth character must be a digit.  The third character must be the / character.  If the user enters anything expect this format then I want to replace what they have typed with an empty space like before.

Any help greatly appreciated thanks

function numInputOnly(ob) 
{
  var invalidChars = /[^0-9]/gi
  
if(invalidChars.test(ob.value)) 
{
  ob.value = ob.value.replace(invalidChars,"");
}


}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lisa B
Lisa B

ASKER

Hi

Thank you very much for the answer and the additional information I really appreciate it - works a treat
Avatar of Lisa B

ASKER

Great answer and further information very helpful as well thanks