JavaScript validation with alternative numeric and alphabetic digits

Sorav Garg

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.

Ayan

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

javascript validation not working for only alphabetic values

From Dev

Validation for numeric data Javascript

From Dev

Validation for numeric data Javascript

From Dev

Javascript password validation at least 2 number digits

From Dev

Convert numeric characters to alphabetic characters

From Dev

Split strings into their alphabetic and numeric components

From Dev

Sorting a .Getfiles in alphabetic and numeric order

From Dev

JavaScript Regex - match last 2 digits and check within numeric range

From Dev

Regex for striping non alphabetic and non numeric characters

From Dev

php array sort numeric first and alphabetic last

From Dev

MIN function on mixed numeric/alphabetic values

From Dev

How to split string into an alphabetic string and a numeric string?

From Dev

JavaScript form validation for ensuring a date of birth is 4 digits long

From Dev

Javascript form validation - ONLY the first character must be numeric

From Dev

Highlight entry if not 17 numeric digits

From Dev

Regular expression for 10 numeric digits

From Dev

XSD validation: total digits and fraction digits

From Dev

Vim: Adding automatic alphabetic and/or numeric index to current file name?

From Dev

How to replace non-alphabetic AND numeric characters in a string in python

From Dev

Python - Pandas - Remove only splits that only numeric but maintain if it have alphabetic

From Dev

R function to convert character statements to numeric in alphabetic order

From Dev

R function to convert character statements to numeric in alphabetic order

From Dev

How to strip non-alphabetic, spaces and numeric characters from a string?

From Dev

How to merge text of alphabetic lines with the numeric lines in shell?

From Dev

How to sort by numeric (logic) ascending but alphabetic order with Debian

From Dev

SQL script to remove zeros between alphabetic and numeric values within a field

From Dev

Laravel set between digits in validation

From Dev

Separate alphabetic characters from a string with javascript

From Dev

Separate alphabetic characters from a string with javascript

Related Related

  1. 1

    javascript validation not working for only alphabetic values

  2. 2

    Validation for numeric data Javascript

  3. 3

    Validation for numeric data Javascript

  4. 4

    Javascript password validation at least 2 number digits

  5. 5

    Convert numeric characters to alphabetic characters

  6. 6

    Split strings into their alphabetic and numeric components

  7. 7

    Sorting a .Getfiles in alphabetic and numeric order

  8. 8

    JavaScript Regex - match last 2 digits and check within numeric range

  9. 9

    Regex for striping non alphabetic and non numeric characters

  10. 10

    php array sort numeric first and alphabetic last

  11. 11

    MIN function on mixed numeric/alphabetic values

  12. 12

    How to split string into an alphabetic string and a numeric string?

  13. 13

    JavaScript form validation for ensuring a date of birth is 4 digits long

  14. 14

    Javascript form validation - ONLY the first character must be numeric

  15. 15

    Highlight entry if not 17 numeric digits

  16. 16

    Regular expression for 10 numeric digits

  17. 17

    XSD validation: total digits and fraction digits

  18. 18

    Vim: Adding automatic alphabetic and/or numeric index to current file name?

  19. 19

    How to replace non-alphabetic AND numeric characters in a string in python

  20. 20

    Python - Pandas - Remove only splits that only numeric but maintain if it have alphabetic

  21. 21

    R function to convert character statements to numeric in alphabetic order

  22. 22

    R function to convert character statements to numeric in alphabetic order

  23. 23

    How to strip non-alphabetic, spaces and numeric characters from a string?

  24. 24

    How to merge text of alphabetic lines with the numeric lines in shell?

  25. 25

    How to sort by numeric (logic) ascending but alphabetic order with Debian

  26. 26

    SQL script to remove zeros between alphabetic and numeric values within a field

  27. 27

    Laravel set between digits in validation

  28. 28

    Separate alphabetic characters from a string with javascript

  29. 29

    Separate alphabetic characters from a string with javascript

HotTag

Archive