• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Reg Exp Question

minestrone

More fingers than teeth
Thanks received
182
I can never work this stuff out.

I am looking for a reg exp that only takes 9 numbers, what I have just now is "\d{9}" and it is letting . - and spaces through.

Anyone know a expression that suits?

Cheers.
 
Where are you evaluating your regexp?
In any case did you try [0-9]{9} or even [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] ?
 
Where are you evaluating your regexp?
In any case did you try [0-9]{9} or even [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] ?

Java server faces code, validateRegExpr tag

[0-9]{9} looks promising, cheers.

I look at reg exp about once a year and always spend 10 minutes trying to get my head round it.
 
Java server faces code, validateRegExpr tag

[0-9]{9} looks promising, cheers.

I look at reg exp about once a year and always spend 10 minutes trying to get my head round it.

Same with me. Have read tons of stuff to make myself an expert at it but still cannot get my head around it at times. It really is the work of devil.
 
I put off learning this stuff for 20 years in IT, but recently was forced to for a gig. It's actually pretty clever.

This I found very helpful:

Regular Expressions Reference - Basic Syntax

Is it a string in Java? I.e. do you mean: "\\d{9}"?

Failing that, I've always found it's better to make it match the start and end:

^\d{9}$
 
regular_expressions.png
 

Advertisers

Back
Top