tags:

views:

54

answers:

3

Hi all
I need a regular expression that accepts only digits and dots, with these conditions:

  1. between digits three must be only one dot '132.632.55'
  2. digits can be repeat in between two dots '.112234563456789.'
  3. the string starts with digits
  4. digits with "." like this '123346547987.' can repeat many times
  5. length of these digits is less than 50 characters

For example: 123456.258469.5467.15546

+1  A: 

From what I can tell from your requirements, you want something like this:

^(\d{1,50}\.)*\d{1,50}$

That is, from one to 50 digits, optionally preceded by any number of groups of one to 50 digits, each group followed by a fullstop. I can't quite tell if you want something like 1233.456 to be invalid, since your requirement #2 implies that only digit groups between dots can contain repeat digits. In such a case, it'd be much simpler to perform the validation of individual digit groups after the fact.

Jon Purdy
Fixed and clarified. @Timwi answered identically while I was still editing.
Jon Purdy
So you got 1 vote from me and u send correct answer!
Rev
A: 

May be this could help

((\d+\.)+\d+)$

But I don't know how you want your 50 length validation. is it excluding "." (dots), is it total character width?

Vishalgiri
+5  A: 

Given all the information in the question, I think this is the regular expression you need:

^(\d{1,50}\.)*\d{1,50}$

This will:

  • require that the string begins and ends with a digit
  • not require that there is a dot in there at all
  • ensure that each run of digits between dots is no longer than 50 digits

If you need it to have at least one dot, change the * to a +:

^(\d{1,50}\.)+\d{1,50}$
Timwi
great you are regular expression `HERO`.
Rev