|
Posted by Noozer on 06/28/05 15:33
Thanks! It's GREATLY appreciated!
"Michael Winter" <m.winter@blueyonder.co.invalid> wrote in message
news:mQawe.57954$G8.27799@text.news.blueyonder.co.uk...
> On 28/06/2005 11:59, Noozer wrote:
>
> > Not sure which newgroup would be best... but since this is being used in
a
> > Javascript function on a web page I guess it could go here...
>
> This group takes many subjects, but a scripting question is still a
> scripting question, and I'd have asked in clj.
>
> [snip]
>
> > Is there a regular expression I can use to ensure that the hyphens are
> > always there?
> > User input ->Result
> > 12312341234 -> 123-1234-1234
> > 123-12341234 -> 123-1234-1234
>
> As simply a test:
>
> /^\d{3}-\d{4}-\d{4}$/.test(accountNumber)
>
> See below for the conversion form.
>
> > How about to always remove hyphens.
> > User input -> Result
> > 123-1234-1234 -> 12312341234
> > 1231234-1234 -> 12312341234
>
> accountNumber = accountNumber.replace(/^(\d{3})-?(\d{4})-?(\d{4})$/,
> '$1$2$3');
>
> If you inserted hyphens into the string literal, you could do the reverse.
>
> Note that the hyphens in the regular expression are followed by a
> question mark (?), which indicates that they are optional. The
> assignment statement above would cope with both input forms you presented.
>
> > Finally, any regular expression to ensure that only 11 characters have
been
> > entered and only digits have been entered.
>
> /^\d{11}$/
>
> > What changes would be need to accept digits AND hyphens.
>
> I think the first case would cover that.
>
> Mike
>
> --
> Michael Winter
> Replace ".invalid" with ".uk" to reply by e-mail.
Navigation:
[Reply to this message]
|