¿Cuál es la expresión regular para detectar una cadena con al menos 6 caracteres y sin espacios en blanco?

I'm still learning regexp and I was wondering what the regexp would look like for detecting a string with at least 6 characters and without any whitespace?

I'm using javascript, so why doesn't this work?

if (VAL.match( /^\S{6,}$/) ) return true;

preguntado el 27 de agosto de 11 a las 17:08

2 Respuestas

You can match a whitespace character with a \s, and a non-whitespace character with \S. So this should work for you:

/^\S{6,}$/

However you didn't specify the flavor of regex you're using. You may need to escape the bracket or use another character class if \S no está disponible.

EDIT (Lars): The question was "at least 6 characters" - modified to {6,}

Respondido 27 ago 11, 21:08

The question was "at least 6 characters", which would be /^\S{6,}$/ - Lars

I'm using javascript...here is my code: if (VAL.match( /^\S{6,}$/) ) return true; it doesn't return true though, even if the input is correct... - zakdances

@yourfriendzak: it should work. Works here. What's the content of VAL? - Sidyll

@sidyll VAL == jQuery.val() I believe - zakdances

Open your console and type VAL to the what's returned. Also, while you're there, try "string".match(/^\S{6,}$/) - Sidyll

Pruebe la siguiente expresión regular:

/^\S{6,}$/

Respondido 27 ago 11, 21:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.