You can use the following regular expression to validate Chinese ID cards in JavaScript:
index.tsx119 chars5 lines
This regular expression checks for either 15 digits or 18 digits, or 17 digits followed by either a digit or the letter X or x. You can use this function to validate ID cards in your JavaScript code as shown below:
index.tsx142 chars7 lines
In this example, we pass a sample ID card number to the validateIDCard()
function and check if it is valid or not. The function returns true
if the ID card is valid, and false
otherwise.
gistlibby LogSnag