Regular Expression to match only odd or even number

Odd Numbers

"^\d*[13579]$"

Even Numbers

"^\d*[02468]$"

Run of Odds with a , and potential whitespace separator

"$\s*(\d*[13579]\s*,\s*)*\d*[13579]$"

Run of Evens with a , and potential whitespace separator

"$\s*(\d*[02468]\s*,\s*)*\d*[02468]$"

Leave a Comment