Create a regular expression to validate at least three characters (accepting spaces)

-1

I'm using this in my code:

<input
    required
    pattern="[a-zA-Z0-9]{3, }"
    title="Por favor, preencha pelo menos 3 caracteres entre letras e números."
    type="text"
    class="form-control"
    id="pesquisa"
    name="q"
    placeholder="Buscar ..."
>
    
asked by anonymous 09.08.2018 / 15:19

1 answer

1

The way that @sam presented works:

<form name="ExpressaoRegular">
   Por favor, preencha pelo menos 3 caracteres entre letras e números.
   <input type="text" name="teste"
      pattern=".{3,}">
   <input type="submit">
</form>
  

Unless there are multiple lines (multiline), then you can   use [/s/S]{3,}

And if you do not want to include special characters and only space, letters and numbers:

<form name="ExpressaoRegular">
   Por favor, preencha pelo menos 3 caracteres entre letras e números.
   <input type="text" name="teste"
      pattern="[\w\d\s]{3,}">
   <input type="submit">
</form>
    
09.08.2018 / 16:02