问题描述
我必须制作正则表达式,不允许字符串以sprecial caracter开头。
例如:
[email protected] - 正确
@ 45gm.com - 错误
我该怎么做?
什么我试过了:
i让这个正则表达式...
string TrNo = txtConsignor.Text.ToString() ;
TrNo = System.Text.RegularExpressions.Regex.Replace(TrNo,[^ a-zA-Z0-9 \\ t],);
txtConsignor.Text = TrNo.TrimStart();
i have to make regular expression which not allow string start with sprecial caracter.
for exampel :
[email protected] - right
@45gm.com - wrong
how can i do this ?
What I have tried:
i have make this regular expression...
string TrNo = txtConsignor.Text.ToString();
TrNo = System.Text.RegularExpressions.Regex.Replace(TrNo, "[^a-zA-Z0-9\\s]", "");
txtConsignor.Text = TrNo.TrimStart();
推荐答案
Match m = Regex.Match(trNo, "^[^a-zA-Z0-9\\s]");
if (m.Success)
{
... report problem to user ...
return;
}
这篇关于字符串的正则表达式不以特殊的字符和空格开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!