Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  13] [ 2]  / answers: 1 / hits: 39953  / 11 Years ago, tue, january 21, 2014, 12:00:00

I know there are a dozen questions at least on this. I am trying to have a simple validation of input for street address using Regex whereby I check for at least two spaces in the input entry. The reason? for the most part us addresses are at least 3 parts, street number, street name, type (lane, drive, ave , st ,etc)



I want to alert the user if the entry doesn't match at least that, if it has more than three spaces, meaning it has more names in the address, that's fine but the minimum not being met necessitates an alert. My latest effort is below, and is not working.



  var addregex = new RegExp(^d{1,6}40([A-Z]{1}[a-z]{1,}40[A-Z]{1}[a-z]{1,})$|^d{1,6}40([A-Z]{1}[a-z]{1,}40[A-Z]{1}[a-z]{1,}40[A-Z]{1}[a-z]{1,})$|^d{1,6}40([A-Z]{1}[a-z]{1,}40[A-Z]{1}[a-z]{1,}40[A-Z]{1}[a-z]{1,}40[A-Z]{1}[a-z]{1,})$);

if (addregex.test($(this).val())) {
alert('is valid');
address.addClass('isvalid');
address.css(border, 1px solid lightgray);
} else {
address.css(border, 2px solid red);
alert(Are you sure this is a valid street address?);
address.focus();
}

More From » jquery

 Answers
15

A simple test is all you need: /^s*S+(?:s+S+){2}/


[#73035] Monday, January 20, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
neildrews

Total Points: 166
Total Questions: 103
Total Answers: 85

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
neildrews questions
Fri, Feb 18, 22, 00:00, 2 Years ago
Tue, Oct 12, 21, 00:00, 3 Years ago
Tue, Mar 23, 21, 00:00, 3 Years ago
Sun, Aug 16, 20, 00:00, 4 Years ago
;