开发者

How to check if user submit Arabic words from a form?

Is there any reliable way to check if user has entered Arabic words into a form and tries to submit it? Can Javascript handle this? Or, only server script 开发者_开发百科like .NET can do this?

I'm thinking that if possible the script should directly prevent the user from inputting Arabic words into the form and show an alert pop up.

Please share any examples if you have any idea how to do it.

Thanks


In Unicode, Arabic characters fall in a specific range. You can use a regular expression in JavaScript to check if a string contains any characters in that range. (You could also do that in c#.) Here's a really helpful tool that will let you select the ranges you want to search for and create a JS-compatible regex for that.

For example, [\u0600-\u06FF\u0750-\u077F] will match any characters that fall in the Unicode ranges for "Arabic" and/or "Arabic Supplement".


You could use the Google Ajax Language API to detect this. Here is an example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜