Use match() in nawk to find digits in number

Hi,

I just need to check whether number of digits in a phone number is 10 or not. If I am not wrong regex will be: [1-9][0-9]{9}

I have to use this inside nawk as this is a small portion of a big program.

nawk '
BEGIN { RS="";FS=";";
regex="[1-9][0-9]{9}";
}
{
    for (i=1;i<=NF;i++) {
      if (match($i,regex))
         {print "matched"}
      else
         {print "not matched"}
    }
}
' input

input file contains:

5134704084;51347040845

Output should be
matched
not matched

but output is:
not matched
not matched

.....
Thanks.

Afaik, nawk uses \{ and \} (this is not POSIX but traditional).
And you will need to use "\\{" and "\\}" in a string.

@ yazu
As I told this is just a small portion of a large program and everything else is working fine inside nawk. I am using 'for', 'if' and other loops in the same nawk and it's working. so my guess is there is a mistake either in regex declaration syntax or regex itself..

thanks.

Oh... I was about using braces in regex in nawk. Try:

regex="[1-9][0-9]\\{9\\}"

nope, its giving wrong results again.

Well... It just means that your version of nawk doesn't support interval expressions in regex at all.
You need

"^[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$"

Thanks yazu, you were right. it worked now.

But there should be some way to do in older version as well, if we need to match 50 digits instead of 10, its irritating.

Anyways Thanks.