简体   繁体   中英

Regex for Alphanumeric, spaces and symbols, Doesn't match like i need

I want to make a regular expression that matches :

-alphanumeric with spaces -these symbols and letters

á é í ó ú ñ Ñ ,.( ) ! - + % $

I tried with this, but it didn't match like i need:

[\w áéíóúñÑ,.\(\)\!\-\+\%\$]

What's wrong in this regex??

I'm using knockoutjs with knockout validation

.extend({pattern:{message:"No valid.",params:"[\w áéíóúñÑ,.\(\)\!\-\+\%\$]"}});

tested on chrome, firefox, IE10 and Safari browser.

You need to escape the special \\ escape character to place an actual \\ in the string. Also, you do not need to escape all these characters, just the ones that have a special meaning within the brackets.

Try with:

"[\\w áéíóúñÑ,.()!\\-+%$]"

this pass ----> "||°°dafsasdf" but this didnt pass the valid ---> "||°°"

Oh, it's because right now as long as a single character in the string matches the regex, it will pass. You have to create a whole pattern match with a defined start and end .

"^[\\w áéíóúñÑ,.()!\\-+%$]*$"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM