John Cappelletti John Cappelletti - 10 months ago 28
jQuery Question

Looking for a regex to to Satisfy the following

I'm looking for a regex or logic in JavaScript to trap the following conditions

If a value begins with a number [space] Street call X

5 Eastern
500 Eastern
25 15th


If NO street number call Y

15th St
N Eastern

Any help or direction would be appreciated.


Here's the regex you're looking for:


Then in JS, use it in the following way:

if (/^\d+\s[A-Z0-9]+[a-z]+/.test(value)) {
else {

value of course is the string that you are testing.


/^\d+\s[A-Z0-9]+[a-z]+/.test('5 Eastern')
// => true

/^\d+\s[A-Z0-9]+[a-z]+/.test('500 Eastern')
// => true

/^\d+\s[A-Z0-9]+[a-z]+/.test('25 15th')
// => true

// => false

/^\d+\s[A-Z0-9]+[a-z]+/.test('15th St')
// => false

/^\d+\s[A-Z0-9]+[a-z]+/.test('N Eastern')
// => false