I want to use JavaScript validation; it will contain only 6 digits but the new thing is that it will like this - A1A1A1
it always start with alphabetic and then numeric and again it means alternative with alphabetic and numeric number with only six digits.
You can use regex for javascript validation. It is very compact and effective. In your case you can try using :
/([A-Za-z]\d){3}/
This means : [A-Za-z] checks if the character is an alphabet. \d checks for a digit. When I am putting the stuff in parenthesis, followed by {3}, it checks for the recurrence of the (...)group thrice.
So in a set of 6 characters, you check thrice for a set of one alphabet, one digit occurrence.
Now you dont want uppercase, then use [a-z] instead of [A-Za-z] in the regular expressions.
You can see an example here :
<!DOCTYPE html>
<html>
<body>
<p>Enter the text you want to validate</p>
<input id="i01"></input>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
text = document.getElementById("i01").value;
alert(/^([A-Za-z]\d){3}$/.test(text));
}
</script>
</body>
</html>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments