0

Hi all. i've been wanting to create a validation that user has to key in for e.g: 10/2009. i want it to have the number and the '/' char.

i tried "^\d+$" which is only for numbers.
".*[/].*" which is only for '/'
"^[0-9a-zA-Z]+$" which doesnt seem to work.
can anyone help me?

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by crishjeny
0

Hi

You can refer following code for Numbers and character validation.

function save() {
if (document.getElementById("numberField").value == "") {
alert("This field must not be empty!");
} else if (!document.getElementById("numberField").value.match(/^\d+$/)) {
alert("Field must be a number!");
}
else if (document.getElementById("publishDate").value == "") {
alert("You must specify a date!");
}
else if (!document.getElementById("publishDate").value.match(/^\d{4}(\-)\d{2}(\-)\d{2}$/)) {
alert("You must specify a date on the form yyyy-dd-mm!");
}
else {
// Functionality to submit form via post or send data via get.
}
}

or just go for this link.

http://www.wohill.com/design/206/JavaScript-validation-for-numbers-and-date.html

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.