Using field script with Painless and Regex

Hello,
I am trying to use painless field script to check if the content of a field has only numeric values, but the script is showing error.
Elasticsearch is set script.painless.regex.enabled: true.
I tried to use it as follows:

if (doc['tamanho.keyword'].size() != 0) {
    if (doc['tamanho.keyword'].value ==~ /[0-9]/ ) {
        return doc['tamanho.keyword'].value
    } else {
        return 0
    }    
} else {
    return 0
}

I am getting the following error:

erro1

And:

if (doc['tamanho.keyword'].size() != 0) {
def m =/[0-9]/.matcher(doc['tamanho.keyword'].value);
if (m.matches() ) {
return m.group(1)
}else{
return 0
}    
}else{
return 0
}

I am getting the following error:

erro2

@tatitozzo can you please include the full error output that you're seeing?

Hi Brandon!

Thanks

Part of the error output is still being cut-off in the screenshot that you posted.