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
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,"");
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great answer and further information very helpful as well thanks
ASKER
Thank you very much for the answer and the additional information I really appreciate it - works a treat