Sometimes, we have to take input from users which should contain only alpha numeric characters.
For example, lets say a Username system which allow only letters and numbers,
Then this can be done with the following Regular Expression
^[a-zA-Z0-9]+$
^
is restrict the start[a-zA-Z0-9]+
is the main part which allow only small a-z
capital A-Z
and numbers with a minimum length of 1 to any extend.$
restrict the endThis can also done by using
^[\w\d]+$
Here
\w
represent the alphabets\d
represent the digitsIf we want to restrict the length to maximum 20 charactes,
^[a-zA-Z0-9]{1,20}$
{1,20}
indicate that the length can be between 1 and 20 including both.