I want to create a register form. Naturally, every user have to choose a username and a password, but I want to, that there are only small a-z characters and numbers 0-9 in the usernames. I want to use regex and javascript. Here is the code:
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
function check(value) {
valid_qwe = /[a-z0-9\-]$/;
trying = valid_qwe.test(value);
alert("The name: " + value + "\nBe allowed: " + trying);
return valid_qwe;
}
</script>
</head>
<body>
<input type="text" autofocus id="qwe" name="qwe" value="" />
<input type="submit" onClick="check(document.getElementById('qwe').value);" value="Check" id="check" />
</body>
</html>
But when I'm trying to test e.g.: apple or #apple always write "true".
What should I do?
Thanks!
\-after number but only/[a-z0-9]$/;