Reputation: 75207
How can I write a JQuery code that test if a given variable between a given variable:
min
and a given variable:
max
also test is it alphanumeric(A-Z, a-z, 0-9) or not?
PS: I can check just length(I will get the value from an input field at a known id) to test between condition, which one is better?
Upvotes: 0
Views: 265
Reputation: 18354
Don't need jquery for this problem. Just plain-old Javascript
function inRange(x, min, max){
return (x >= min && x <= max);
}
function isAlphanumeric(str){
return /^[A-Za-z0-9]+$/g.test(str);
}
alert(inRange(50, 0, 100)); //shows true
alert(isAlphanumeric("me & you")); //shows false
Upvotes: 1