Tema: Re: Regex validation
Autorius: GP
Data: 2010-08-13 15:19:34
hmm... o man norejosi viska sukelti i viena filtra....

On 08/13/10 12:09, rr wrote:
>> Sveiki,
>>
>> ar yra cia kas su regular expression dirbes?
>>
>> Reikia parasyti tel nr patikrinima
>>
>> •     2 – 20 digits
>> •     Only one instance of “+”, and the “+” (if exists) must be the
>> first character
>> •     Only one instance of “-”, and if exists it must not be the first
>> character
>> •     Only one instance of “/”and if exists it must not be the first
>> character •     No other characters allowed
>>
> 
> perlu:
> $nr = '+370-1258';
> print "ok" if 
>    ($nr =~ /^(\+|\d)[\-\/0-9]+$/ &&
>     $nr =~ tr/\-/\-/ <= 1 &&
>     $nr =~ tr/\//\// <= 1 &&
>     $nr =~ tr/[0-9]/[0-9]/ >= 2 &&
>     $nr =~ tr/[0-9]/[0-9]/ <= 20);    

-- 
GP