regex.test is not a Function

Asked

Viewed 54 times

0

I need to apply a mask that formats both landline and phone.

I tried to:

<input [pattern]="customPatterns" type="text" class="form-control" id="numero" name="numero" [(ngModel)]="empresa.numero">

and in the component:

  public customPatterns = { pattern: new RegExp(/^(?:(?:\+|00)?(55)\s?)?(?:\(?([1-9][0-9])\)?\s?)?(?:((?:9\d|[2-9])\d{3})\-?(\d{4}))$/)};

But I get:

RROR Typeerror: regex.test is not a Function

1 answer

-1

Are you wearing ngmask? I believe it is necessary to inform the parameters:

code meaning 0 digits (like 0 to 9 Numbers) 9 digits (like 0 to 9 Numbers), but optional A Letters (uppercase or lowercase) and digits S only Letters (uppercase or lowercase)


Try:

public customPatterns = {'A': { Pattern: new Regexp(/ (?: (?:+| 00)? (55) s? )? (?: (? ([1-9][0-9]))? s? (?: (?: 9 d|[2-9]) d{3})-? ( d{4}))$/)}};

  • 1

    There is a mixture of English and Portuguese in your reply or is it my impression?

  • It is an excerpt from the ngx-Mask lib

  • But if not, try removing the object from the customPatterns: public customPatterns = new Regexp(/ (?: (?:+| 00)? (55) s? )? (?: (? ([1-9][0-9]))?\ s? )? (?: ((?: 9\d|[2-9])\d{3})-? (\d{4}))$/);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.