admin管理员组文章数量:1316980
how is validation only for type word english or persian or number, each separate in input?
i not want use of plugin.
only type english -> hello
only type persian -> سلام
only type number -> 123123
how is validation only for type word english or persian or number, each separate in input?
i not want use of plugin.
only type english -> hello
only type persian -> سلام
only type number -> 123123
3 Answers
Reset to default 91. English only
var only_english = 'abcdAbDKDk',
mixed = 'سلامaaSDSD';
if (/[^A-Za-z]/g.test(only_english)) {
alert('"only_english" contains characters other than English');
} else {
alert('"only_english" contains only English characters');
}
if (/[^A-Za-z]/g.test(mixed)) {
alert('"mixed" contains characters other than English');
} else {
alert('"mixed" contains only English characters');
}
2. Persian only
var only_persian = 'سلام',
mixed = 'سلامaaSDSD';
if (/[^\u0600-\u06FF]/g.test(only_persian)) {
alert('"only_persian" ontains characters other than Persian');
} else {
alert('"only_persian" ontains only Persian characters');
}
if (/[^\u0600-\u06FF]/g.test(mixed)) {
alert('"mixed" contains characters other than Persian');
} else {
alert('"mixed" contains only Persian characters');
}
3. Only numbers
var only_numbers = '12334',
mixed = '3124adqad';
if (/[^0-9]/g.test(only_numbers)) {
alert('"only_numbers" does not contain only numbers');
} else {
alert('"only_numbers" contains only numbers');
}
if (/[^0-9]/g.test(mixed)) {
alert('"mixed" does not contain only numbers');
} else {
alert('"mixed" contains only numbers');
}
You should use RegularExpressionValidator and set it's validationExpression to : Only English = [A-Za-z]+ Only Number =\d+
var only_persian = 'salam 1ایران';
if (/^[A-Za-z\u0600-\u06FF\s]*$/.test(only_persian)) {
alert(true);
} else {
alert(false);
}
本文标签: javascriptvalidation only for type word english or persian or numberStack Overflow
版权声明:本文标题:javascript - validation only for type word english or persian or number? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742010521a2412801.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论