正则表达式为只接受波斯字符 [英] regex for accepting only persian characters

查看:398
本文介绍了正则表达式为只接受波斯字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一种形式,它的一个自定义的验证应该只接受波斯字符...我用下面的code:

I'm working on a form which one of it's custom validator should only accept persian characters...I used the following code:

    var myregex = new Regex(@"^[\u0600-\u06FF]+$");
    if (myregex.IsMatch(mytextBox.Text))
    {
        args.IsValid = true;
    }
    else
    {
        args.IsValid = false;
    }

但似乎只检查阿拉伯文字工作,它并不包括所有的波斯字符(它缺乏这四个گ,چ,پ,ژ)...有没有解决这一问题的方法?

but it seems it only work for checking arabic characters and it doesn't cover all persian characters (it lacks these four گ,چ,پ,ژ )... is there a way for solving this problem?

推荐答案

你所目前在你的正则表达式是一个标准阿拉伯语符号范围。对于其他字符您需要将它们单独添加到正则表达式。下面是他们的codeS:

What you currently have in your regex is a standard Arabic symbols range. For additional characters your need to add them to the regex separately. Here are their codes:

ژ \uFB8A
پ \u067E
چ \u0686
گ \u06AF

所以,这一切的一切,你应该有

So all in all you should have

^[\u0600-\u06FF\uFB8A\u067E\u0686\u06AF]+$

这篇关于正则表达式为只接受波斯字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆