gpt4 book ai didi

javascript - 仅验证类型单词英语或波斯语或数字?

转载 作者:行者123 更新时间:2023-12-01 00:46:17 26 4
gpt4 key购买 nike

如何仅对类型单词英语、波斯语或数字进行验证,每个单词在输入中都是单独的?
我不想使用插件。

仅输入英语 -> 你好
仅输入波斯语 -> มม
仅输入数字 -> 123123

最佳答案

1. 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');
}

关于javascript - 仅验证类型单词英语或波斯语或数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6730211/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com