REGULAR EXPRESSION TO MATCH MAXIMIUM OF FIVE WORDS

Pravesh Singh

Total Post:412

Points:2888
Posted by  Pravesh Singh
 967  View(s)
Ratings:
Rate this:

I have a regular expression

^[a-zA-Z+#-.0-9]{1,5}$

which validates that the word contains alpha-numeric characters and few special characters and length should not be more than 5 characters.

How do I make this regular expression to accept a maximum of five words matching the above regular expression.

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: Regular expression to match maximium of five words

    Hi Pravesh, 


    try this:

    ^[a-zA-Z+#\-.0-9]{1,5}(\s[a-zA-Z+#\-.0-9]{1,5}){0,4}$

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!