Check if textbox contains invalid characters
javascript, regex
Solution
You are using `.value` twice:
document.getElementById("first_name").value
and `if(inputtxt.value.match(letters))`
Remove one of them.
Problem
I having a issue trying to check if a textbox only contains a-z 0-9 values using JavaScript. I have a textbox on my page: ``` <input type="text" id="first_name" class="first_name" value=""> ``` I am using the following JavaScript Function to check my textbox: ``` // Function to check letters and numbers function alphanumeric(inputtxt) { //alert(inputtxt); var letters = "/^[0-9a-zA-Z]+$/"; if(inputtxt.value.match(letters)) { alert('accepted'); } else { alert('Please input alphanumeric characters only'); return false; } } ``` And I am calling my function like this: ``` var test = alphanumeric(document.getElementById("first_name").value); ``` However nothing is happening. If I alert 'inputtxt' in my alphanumeric function it returns my value I have in my textbox so I know there is a value to be checked, but it doesn't seem to go on from there. Does anyone know where I have gone wrong? I am trying to do this with JavaScript (no jQuery).