Home > Mobile >  preg_match with ' and ñ
preg_match with ' and ñ

Time:11-21

i want a text that only accept letters upper/lower, accents (Á,á,É,é,Í,í,Ó,ó,Ú,ú) and character spain 'ñ,Ñ'

if (!preg_match("/[a-zA-Z]/", $_POST["text"]))
    $er = "Introduce un nombre válido";

Where i must put this charácter?

if (!preg_match("/[a-zA-Z][Á,á,É,é,Í,í,Ó,ó,Ú,ú][ñ]/", $_POST["text"]))
    $er = "Introduce un nombre válido";

This doesnt work, where is the wrong?

Thanks

CodePudding user response:

try this match.

if (!preg_match("/^[a-zA-ZÁáÉéÍíÓóÚúñ] $/", $_POST["text"]))
    $er = "Introduce un nombre válido";

regex one [ ] expression is one group.

  •  Tags:  
  • php
  • Related