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

Asked

Viewed 68 times

-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 ..."
>
  • Try it like this .{3,}

  • does not work regex must accept blanks

  • the dot accepts any character.

1 answer

1


The way @sam presented it 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 utilise [/s/S]{3,}

And if you don’t 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>

Browser other questions tagged

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