I want a pattern with letters and numbers only.
This is how I do it...
JavaScript file:
var pattern_checked = checkPattern();
function checkPattern(){
var elem = document.getElementById("name");
var pattern = elem.getAttribute("[a-zA-Z0-9_]");
var re = new RegExp(pattern);
if (re.test(elem.value)) {
return true;
} else {
return false;
}
}
But in both the cases, I'm getting false.
What is wrong in this code?
[a-zA-Z0-9_]
this in your html .i think its apattern attr
– Ilbertelem.getAttribute("[a-zA-Z0-9_]")
will return??? – Cyteelem.getAttribute("attributeName")
would return your pattern. – Tasteless