Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript and regexp

Status
Not open for further replies.

zillaZ

Programmer
Joined
Dec 18, 2009
Messages
3
Location
FI
Hi all.

I'n new in regexp and I wonder how can check is value valid.

valid value is 7-9 numbers long and in the beginning there can be #-character

So values: 4398733 and #384 are ok, but
values 3455 or #477938742983 aren't.

I have tried something like this, but this is not correct
Code:
val.match(/^\#\d{7-9}$/))
 
Hi

zillaZ said:
So values: 4398733 and #384 are ok
Are you sure ? "#384" is not 7-9 character long.

Anyway
[ul]
[li]no need to escape #[/li]
[li]zero or one of something can be specified with the [tt]?[/tt] quantifier[/li]
[li]in the [tt]{}[/tt] quantifier the limits are separated with comma ( , )[/li]
[/ul]
Code:
val[teal].[/teal][COLOR=darkgoldenrod]match[/color][teal]([/teal][fuchsia]/^#?\d{7,9}/[/fuchsia][teal])[/teal]


Feherke.
 
You are right feherke.

#384 is not valid value. stupid me.

And thank you very much for your respone.
 
Hi

Oops. Now I see that somehow I removed the [tt]$[/tt] for matching at the end. That is still necessary :
Code:
val[teal].[/teal][COLOR=darkgoldenrod]match[/color][teal]([/teal][fuchsia]/^#?\d{7,9}$/[/fuchsia][teal])[/teal]

Feherke.
 
Thanks for the correction feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top