Odp: [Javascript] excluding special characters in a form
grzegorz.stasica at delphiauto.com
grzegorz.stasica at delphiauto.com
Wed Mar 13 01:11:34 CST 2002
Hi
For me the best solution which I find myself instantly is Regular Expression.
the snippet is as follow:
function CheckCreditCard(form) {
var re = RegExp(form.regexp.value)
var input = form.main.value
if (input.search(re) !=-1) {
alert ("ok")
} else {
alert ("Error")
}
}
you can customize this function as you wish remember only that
form.regexp.value should be replaced with some regular expression for credit
card e.g 1111-1111-1111-1111 regular expresion should be :
/\d{4}[\-]\d{4}[\-]\d{4}[\-]\d{4}/
if yoy don't remember below is short explenation
/ - begin or end of regular expression
\d{4} - you expect to have 4 numbers
[\-] - you expect "-"sign
Rgs.
More information about the Javascript
mailing list