Using RegExpressions to validate GPA
This is the shortest expression:
/^[0-4]\.\d\d$/
Explanation:
^ - Start of line
[0-4] - One digit in the range 0-4
\. - A dot, which needs to be escaped with a backslash.
Without the backslash it means "any character apart from line break"
\d\d - Two digits (any value from 0-9)
$ - End of line
Try like this:
/^[0-4]\.\d{2}$/