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?

i found the solution already. :D

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.