必须由6到10个字符组成的字符串的正则表达式怎么写?

如题所述

const string pattern = @"^\w{6,10}$"; // 允许6-10个可见字符
const string pattern = @"^[a-zA-Z]{6,10}$"; // 允许6-10个英文字符
const string pattern = @"^[\da-zA-Z]{6,10}$"; // 允许6-10个英文字符或者数字
const string pattern = @"^\d{6,10}$"; // 允许6-10个数字

Regex regex = new Regex(pattern, RegexOptions.Singleline | RegexOptions.Compiled)
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-04-18
^[\s\S]{6,10}$
第2个回答  2010-04-18
^\w{6,10}$
相似回答