Re: Regular expression to test and limit number of characters
- From: "Evertjan." <exjxw.hannivoort@xxxxxxxxxxxx>
- Date: 28 Feb 2008 14:14:46 GMT
RobG wrote on 28 feb 2008 in comp.lang.javascript:
RobG wrote:
Bart Van der Donck wrote:
Evertjan. wrote:
/^[\dA-Z]{9,12}$/.test(str) && str.replace(/\d/g,'').length<2
Identical, but more terse:
/^\d{9,12}$/.test(str.replace(/[A-Z]/,1))
Where does the (optional or mandatory) letter fit in the first RegExpr?
Ah, OK, I got it - the replace takes care of it first. I'm a bit slower
than usual tonight.
I like Bart's solution.
That's what the joy of programming is about.
[But it does not cover the mandatoriness of an upperalpha! ;-) ]
An alternative not using test():
!str.replace(/[A-Z]/,1).replace(/\d{9,12}/,'')
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
.
- References:
- Regular expression to test and limit number of characters
- From: Sharkie
- Re: Regular expression to test and limit number of characters
- From: Bart Van der Donck
- Re: Regular expression to test and limit number of characters
- From: Evertjan.
- Re: Regular expression to test and limit number of characters
- From: Bart Van der Donck
- Re: Regular expression to test and limit number of characters
- From: RobG
- Re: Regular expression to test and limit number of characters
- From: RobG
- Regular expression to test and limit number of characters
- Prev by Date: Re: block writing
- Next by Date: Re: block writing
- Previous by thread: Re: Regular expression to test and limit number of characters
- Next by thread: Re: Regular expression to test and limit number of characters
- Index(es):