Pattern regex in HTML5 prevent white space?

Viewed 1556

I have regex for two different fields. Both will evaluate correct values but none of them prevents user of entering white space. For example in Gender field user can simply enter white space and submit the form. I want to prevent user of entering white space. Here is my regex:

Gender pattern="*[MmFf]?*"  #This field should allow M or F letter lower or upper case. Nothing else should be allowed. This field is 1 character only.

Grade pattern=" *(0?[0-9]|1[0-2]|[A-Z]{1,2})? *" #This should allow 01 or 1 and something like this PK or pk. No white space.

I'm not sure how to prevent white space in HTML5 pattern. if anyone knows how to solve this problem please let me know. Thanks.

1 Answers
Related