JSFiddle - React, Tailwind, and code Playground
by thetenfold
JavaScript
/*
Should return true if any of these are true:
1) there are at least two letters, followed by a comma, followed by exactly two letters
2) there are at least two letters, followed by a comma and a whitespace, followed by exactly two letters
3) there are five numbers
*/
var str="ab, ab"; // this should return true
//var str="abc, ab"; // this should return true
//var str="abc,ab"; // this should return true
//var str="ab,ab"; // this should return true
//var str="12345"; // this does return true
//var patt1 = /^[a-z]{2,},\s*[a-z]{2}$/i; - city/state only; works
//var patt1 = /[0-9]{5}/; - zip only; works
var patt1 = /(^[a-z]{2,},\s*[a-z]{2}$)|(^\d{5})/i; //combined - only zip returns true
alert( patt1.test(str) );