normand
normand

Reputation: 21

Check for valid file name with regex

I'm try to verify filenames with this schema: <letter>-<digits>.html. For example, t-32782.html or f-484774.html. One letter then many digits then ".html".

Upvotes: 0

Views: 1084

Answers (4)

theazureshadow
theazureshadow

Reputation: 10049

Don't know what flavor of regex you're using, but this should work for a number of them.

/^\w-\d+\.html$/

Upvotes: 1

Ruel
Ruel

Reputation: 15780

If the first letter is always lowercase:

/^[a-z]-[0-9]+\.html$/

If it can be lowercase or uppercase:

/^[a-zA-Z]-[0-9]+\.html$/

Upvotes: 1

cdhowie
cdhowie

Reputation: 168988

/^[a-zA-Z]-[0-9]+\.html$/

Upvotes: 0

Explosion Pills
Explosion Pills

Reputation: 191729

/[a-z]\-[0-9]+\.html/

Upvotes: 0

Related Questions