Check if textbox contains invalid characters

KodeBurner

New Member
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:\[code\]<input type="text" id="first_name" class="first_name" value="">\[/code\]I am using the following JavaScript Function to check my textbox:\[code\]// Function to check letters and numbersfunction 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;}}\[/code\]And I am calling my function like this:\[code\]var test = alphanumeric(document.getElementById("first_name").value);\[/code\]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).
 
Top