Me *_*hdi 2 javascript jquery jquery-validate
如何仅对类型字英语或波斯语或数字进行验证,每个单独输入?
我不想使用插件.
只输入英语 - >你好
只输入波斯语 - >سلام
只输入类型号 - > 123123
1. 仅限英语
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');
}
Run Code Online (Sandbox Code Playgroud)
2. 仅限波斯语
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');
}
Run Code Online (Sandbox Code Playgroud)
3. 只有数字
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');
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3313 次 |
| 最近记录: |