Hi I tried the following code in javascript,
if(/[^0-9a-zñáéíóúü]/i.test(string))
{
alert("oK WITH THE INPUT");
}
else
{
alert("error");
}
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).
Please help me in this.
Thanks in advance.
Regular expressions are easy to learn, self-containing (its syntax is rarely changed or updated), very powerful and language agnostic, since they work for all natural languages and with majority of programming languages.
Special Regex Characters: These characters have special meaning in regex (to be discussed below): . , + , * , ? , ^ , $ , ( , ) , [ , ] , { , } , | , \ . Escape Sequences (\char): To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ).
Description. [a-zA-Z] matches any character from lowercase a through uppercase Z.
Using regular expressions in JavaScript. Regular expressions are used with the RegExp methods test() and exec() and with the String methods match() , replace() , search() , and split() . Executes a search for a match in a string. It returns an array of information or null on a mismatch.
if(/^[0-9a-zñáéíóúü]+$/i.test(string))
{
alert("oK WITH THE INPUT");
}
else
{
alert("error");
}
+
quantifier
^
and $
anchors^
)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With