I’m working on Dynamic page where input#first.val() is dynamic.
Basically values I’ll be getting are either Device Name or Device resolution..
Say if input#first.val() is the Device name, like "iPad", then I dont need any further action.
But if input#first.val() is the Device resolution, like "1024 X 768", then I want to alert the user.
So how do I detect if input#first.val() is the Device resolution?
Also, the Device resolution will be dynamic, so it could look like any of these…
- “1024 X 768“
- “480 X 640“
- “320 X 480“
The common thing will be “_ X _“
So how do I detect “_ X _” within input#first.val() and alert the user?
Maybe with :contains and string object?
<input type="text" id="first" name="name" value=""/>
You can test it with a regular expression:
By way of explanation, this regular expression is:
If you want to require that there is nothing else but the resolution numbers, you can use this:
If you want to require that each number is at least 3 digits, you can use this:
Also, is there any reason to use “input#first” as the selector instead of just “#first”? The shorter version is less work for the selector engine and since ids must be unique in the page it should generate the same result unless you were somehow trying to filter out a #first that wasn’t on an input tag (which seems unlikely).