在javascript中允许带有西班牙语正则表达式的字母数字?
问题描述:
我在 javascript 中尝试了以下代码,
Hi I tried the following code in javascript,
if(/[^0-9a-zñáéíóúü]/i.test(string))
{
alert("oK WITH THE INPUT");
}
else
{
alert("error");
}
但我得到的结果是 OK ,即使我在字符串中输入了 @ 字符.我不知道为什么.
But I am getting a result OK , even I entered the @ characters in my string. I dont why.
我的目标是允许使用字母数字(英语和西班牙语).
My aim is to allow alphanumeric(English and spanish).
请帮我解决这个问题.
提前致谢.
答
if(/^[0-9a-zñáéíóúü]+$/i.test(string))
{
alert("oK WITH THE INPUT");
}
else
{
alert("error");
}