In my form I have a text field in which user type date. Good habit tells me to not let user to put anything other then dgit and '-' symbol in the field.
However i have a bit problem with implementing such feature. So far I Have a field which accept only digits. If user try to put in field letter, this letter is being removed. But the point is to create \[code\](DD-MM-YYYY)\[/code\]format so field have to accept '-' symbol.
Here is my code:\[code\]<input type="text" name="test3" placeholder='DD-MM-YYYY' onkeyup="if (/\D/g.test(this.value)) this.value = http://stackoverflow.com/questions/15547344/this.value.replace(/D/g,'')"/>\[/code\]i tried put \[code\]|\-\[/code\] into regex but with no success. Can anyone point me where I am doing mistake?
However i have a bit problem with implementing such feature. So far I Have a field which accept only digits. If user try to put in field letter, this letter is being removed. But the point is to create \[code\](DD-MM-YYYY)\[/code\]format so field have to accept '-' symbol.
Here is my code:\[code\]<input type="text" name="test3" placeholder='DD-MM-YYYY' onkeyup="if (/\D/g.test(this.value)) this.value = http://stackoverflow.com/questions/15547344/this.value.replace(/D/g,'')"/>\[/code\]i tried put \[code\]|\-\[/code\] into regex but with no success. Can anyone point me where I am doing mistake?