C#正则表达式只允许字母和数字 [英] C# Regex to allow only alpha numeric

查看:1379
本文介绍了C#正则表达式只允许字母和数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的正则表达式 ^ [A-ZA-Z0-9] + $ 这将允许字母数字字符。这里的问题是,如果我只输入数字字符,如897687,那么正则表达式匹配依然。我不希望这样的事情发生。应的至少一个字母和它应该与字母开始。比如像A343或a98bder或a4544fgf343

I have the following regex ^[a-zA-Z0-9]+$ which would allow alpha numeric characters. The problem here is that if I enter only numeric character like "897687", then the regex still matches. I don't want that to happen. There should be at least one alphabet and it should start with an alphabet. For example like "a343" or "a98bder" or "a4544fgf343"

这将是巨大的,如果你能帮助我提高我对这个正则表达式。

It would be great if you could help me to improve my regex for this.

推荐答案

听起来像是你想要的:

^[a-zA-Z][a-zA-Z0-9]*$

这篇关于C#正则表达式只允许字母和数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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