Could someone explain me why this scripts works? I've searched after a description of the 'test'-function, but I simply can't find one. And the syntax of the email-data doesn't make any sense to me...
email is a RegExp object, test() is a method that runs the RegExp pattern (supplied at creation time) against the value passed to it. If the value matches, it returns true/non-zero and false/zero if it fails.
Whats wrong with this code? The function returns the alert 'Have to be four digits' if I type less than four digits, but if I type more, it still returns the 'OK'... I would like it to return 'OK' only if there are exactly four digits...
function isOrderNumber(formObj){
var str = formObj.value;
alert(str);
var orderNumber = /\d{4}/
if(orderNumber.test(str)){
alert('OK');
}
else
alert('Have to be four digits');
}