I’m using jQuery to validate an input form. I have values in my input boxes Name, Telephone etc which are ghost hints as guides for the user.
My issue arises with the jQuery validation, as it is recognising this ghost text as an input, and therefore processing the form before the user enters anything.
Input Field:
<input class="validate[required,custom[name]] text-input" type="text" name="Name" id="Name" value="Name" onfocus="if
(this.value==this.defaultValue) this.value=''; " onblur="if(this.value=='') this.value=this.defaultValue;" />
Regex in Validation Engine js file:
"name":{
"regex":"/(Name)$/",
"alertText":"Please enter your name"},
My goal is this:
if input field = “Name” {display JS error}
else: process field
How would I do this to match “Name”. Additional Question: I also have input fields with multiple words as ghost text such as “Your Phone Number”. Would the Regex be different for this?
Thanks in advance
You’re quite correct Tom – we are getting our wires crossed – You effectively want to negate the regex so use…
This uses a negative lookahead to match anything (ie validate anything) other than
Name.Likewise for the phone number one…
Of course, these won’t actually validate that they are valid names (what are they ? :)) or valid phone numbers just that they aren’t
NameorYour Phone Numberexactly…