I've toyed with this for the last hour and am finally asking for some advice/help on what's causing this issue. I'm creating a small fallback using RegEx, the first input works fine, but the second returns undefined. Here's the HTML:
<input type="email" value="[email protected]" />
<input type="text" pattern="[A-Za-z]{3}" value="ABC" />
You'll see from the jsFiddle and Console that it prints 'Success' for the type="email" input, but returns undefined for the pattern fallback. I basically want to reuse the same function and pass the parameters into it and get the value returned dynamically.
I have a feeling this might be the issue line:
var patternFallback = $(this).attr('pattern')
... Perhaps it somehow needs 'converting' for the JS to read it as RegEx?
Here's my jsFiddle if you can help, and thank you! The script is a section of the full code, which includes the problem area, the loop through elements and the variables I'm passing through the function: http://jsfiddle.net/fTk7e/
Many thanks in advance.
$(this).attr('pattern')outside of any sort of event handler. Thereforethisis not your element.