/    Sign up×
Community /Pin to ProfileBookmark

Could I have some regexp help? :)

I want to have a few functions going:

1) I would like it so that phone numbers have to be entered in the (00000) 000000 format
2)I would like it so that the Full Name and Company Name text boxes can have multiple words and “-” to be entered into them
3) And I would like it so that text in the address box has to start off with a number and then any words are allowed afterwards ?

Any help would be appreciated! ?

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@WolfShadeMar 16.2012 — The RegEx masks that you are looking for seem fairly straight-forward. I have not tested any of these.

A left-parenthesis, five digits, right-parenthesis, a space, followed by six digits:
[CODE]
phoneMask = /^(d{5}) d{6}$/;
[/CODE]

Name and Company should allow ONLY letters, spaces, and hyphens:
[CODE]
nameMask = /^[ a-z-]$/i;
[/CODE]

Address MUST start with a number, then any words:
[CODE]
addressMask = /^[1-9][0-9]{0,7} [ a-z]$/i; // allows up to 8 digits at start of string and cannot begin with 0
[/CODE]
Copy linkTweet thisAlerts:
@007JulienMar 17.2012 — To be a little less rigorous than the machine and to get immediately to the point, this kind of test can be proposed for the Phone number...

[CODE]<label >Phone number <input value="" onblur="if ((t=this.value.replace(/D/g,'')).length!=11) alert('Please, the number has not 11 digits !');else this.value=t.replace(/(d{5})(d{6})/,'($1) $2')"> (11 digits) </label>[/CODE]Then the user can write is number with separator, brackets or other signs. If he make a mistake, I will probably modify the digits by preserving the format...

For the address, we have in France bis or ter numbers and other Post office box !
Copy linkTweet thisAlerts:
@APD1993authorMar 19.2012 — The RegEx masks that you are looking for seem fairly straight-forward. I have not tested any of these.

A left-parenthesis, five digits, right-parenthesis, a space, followed by six digits:
[CODE]
phoneMask = /^(d{5}) d{6}$/;
[/CODE]

Name and Company should allow ONLY letters, spaces, and hyphens:
[CODE]
nameMask = /^[ a-z-]$/i;
[/CODE]

Address MUST start with a number, then any words:
[CODE]
addressMask = /^[1-9][0-9]{0,7} [ a-z]$/i; // allows up to 8 digits at start of string and cannot begin with 0
[/CODE]
[/QUOTE]


Could the name one be tweaked so that only 2 words are allowed (e.g. John Smith?) ?
Copy linkTweet thisAlerts:
@007JulienMar 19.2012 — To allow only two words, it enough to allow one (or more to reduce at one ?) space between two words composed with letters, hyphens and perhaps apostrophe (for John O'Neil).
Copy linkTweet thisAlerts:
@WolfShadeMar 19.2012 — Could the name one be tweaked so that only 2 words are allowed (e.g. John Smith?) ?[/QUOTE]
Sure. I guess do one for company and one for personal name.

[CODE]
personNameMask = /^[a-z]{1}[a-z-] [a-z]{1}[a-z-]$/i;
companyNameMask = /^[ a-z-]$/i;
[/CODE]
Copy linkTweet thisAlerts:
@APD1993authorMar 19.2012 — The RegEx masks that you are looking for seem fairly straight-forward. I have not tested any of these.

A left-parenthesis, five digits, right-parenthesis, a space, followed by six digits:
[CODE]
phoneMask = /^(d{5}) d{6}$/;
[/CODE]

Name and Company should allow ONLY letters, spaces, and hyphens:
[CODE]
nameMask = /^[ a-z-]$/i;
[/CODE]

Address MUST start with a number, then any words:
[CODE]
addressMask = /^[1-9][0-9]{0,7} [ a-z]$/i; // allows up to 8 digits at start of string and cannot begin with 0
[/CODE]
[/QUOTE]


Could the addressMask be tweaked so that I can have addresses such as 123 Fake Street? At the moment, I can't seem to do that :/
Copy linkTweet thisAlerts:
@JustWhateverMar 19.2012 — This link may help. It lets you type in your regex and then type in what you want to test to see if it works.

http://www.regular-expressions.info/javascriptexample.html
Copy linkTweet thisAlerts:
@APD1993authorMar 19.2012 — This link may help. It lets you type in your regex and then type in what you want to test to see if it works.

http://www.regular-expressions.info/javascriptexample.html[/QUOTE]


Yeah, it seems that the regexp given doesn't work :/
×

Success!

Help @APD1993 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...