如何使用 Javascript 验证 html 表单中文本类型的输入标签,其内容为阿拉伯语/英语/数字?
如何使用 Javascript 验证 html 表单中文本类型的输入标记,其内容将是以下之一:-
- 仅限阿拉伯语或英语字符 -OR-
- 仅阿拉伯文和英文字符 -或
- - 仅
- 阿拉伯文字符 -或 - 仅英文字符 -
- 或 -仅数字 -或 -
- 仅阿拉伯文字符和数字 -或 - 仅
- 英文字符和数字 -或 - 仅
- 阿拉伯文或数字 -或 -
- 英文字符或仅数字 -或 -
- 仅阿拉伯语或英语字符或数字 -或-
- 电话号码 -或-
- 电子邮件 -或-
- 以特定字符(如“A”)开头的英语字符串 -或- 以特定字符(如“A”)
- 结尾的英语字符串 -或- 以特定字符(如“A”)结尾的
- 英语字符串包含特定字符(如“A”)-或-
- 英语字符串不包含特定字符(如“A”)
提前致谢..
How to validate using Javascript an input tag of type text in an html form that the content of it will be one of the following:-
- Arabic or English Characters ONLY -OR-
- Arabic and English Characters ONLY -OR-
- Arabic characters only -OR-
- English Characters only -OR-
- Number only -OR-
- Arabic Characters and Number only -OR-
- English Characters and Number only -OR-
- Arabic or Number ONLY -OR-
- English Characters or Number ONLY -OR-
- Arabic or English Characters or Number ONLY -OR-
- Phone Number -OR-
- Email -OR-
- English string that starts with specific character like 'A' -OR-
- English string that ends with specific character like 'A' -OR-
- English string that contains specific character like 'A' -OR-
- English string that does not contain specific character like 'A'
Thanks in advance ..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我需要“英语”、“阿拉伯语”和“数字”字符的定义。
英语正则表达式:
[a- zA-Z]
RegExp:
/[\u0600-\u06ff\ufb50-\ufdff\ufe70-\ufeff]/
0-9
)。正则表达式:
\d
(等于[0-9]在 JavaScript 中)
^
和$
进行匹配。汇集:
/^[a-zA-Z\u0600-\u06ff\ufb50-\ufdff\ufe70-\ufeff]+$
/^[\u0600-\u06ff\ufb50-\ufdff\ufe70-\ufeff]+$/
/^[ a-zA-Z]+$/
/^\d+$/
/^[\du0600-\u06ff\ufb50-\ufdff\ufe70-\ufeff]+$
/^[\dA-Za-z]+$/
/^[a-zA-Z\d\u0600-\u06ff\ufb50-\ufdff\ufe70-\ufeff]+$/
<代码>^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[AZ]{2,4}$ < super>源代码 2(非常基本的邮件正则表达式)
/^A/
/A$/
/A/
^[^A]+$
当然,英文字符集应该包含比
a-zA-Z
如果您正在验证句子。我建议使用[\x20-\x7e]
而不是[a-zA-Z]
,这样常用的标点符号也可用。参考资料 / 另请参阅
First, I need a definition of "English", "Arabic" and "Numbers" characters.
English RegExp:
[a-zA-Z]
RegExp:
/[\u0600-\u06ff\ufb50-\ufdff\ufe70-\ufeff]/
\d
(in JavaScript:0-9
).RegExp:
\d
(equals[0-9]
in JavaScript)^
and$
, using Regular expressions.Brought together:
/^[a-zA-Z\u0600-\u06ff\ufb50-\ufdff\ufe70-\ufeff]+$
/^[\u0600-\u06ff\ufb50-\ufdff\ufe70-\ufeff]+$/
/^[a-zA-Z]+$/
/^\d+$/
/^[\du0600-\u06ff\ufb50-\ufdff\ufe70-\ufeff]+$
/^[\dA-Za-z]+$/
/^[a-zA-Z\d\u0600-\u06ff\ufb50-\ufdff\ufe70-\ufeff]+$/
^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$
source 2 (very basic mail RegExp)/^A/
/A$/
/A/
^[^A]+$
Of course, the English character set should include more characters than
a-zA-Z
if you're validating sentences. I recommend to use[\x20-\x7e]
instead of[a-zA-Z]
, so commonly used punctuation characters are also available.References / See also