允许字母、数字、小数、空格和下划线的正则表达式模式


Regex pattern allowing alphabets, numbers, decimals, spaces and underscore

我不擅长正则表达式模式。我必须对字符串进行验证,以允许

only alphabets, numbers, decimals, spaces, comma and underscore 

允许字母和空格,我有/^[a-zA-Z][a-zA-Z''s]+$/请帮助我在一个模式中创建上述所有条件。

谢谢

这个正则表达式应该可以满足您的需求

'[a-zA-Z0-9_. ,]*'

在正则表达式中,我指定了范围a到z、a到z(大写)、0到9和单个字符_、小数点"。"、空格和逗号。

如果您想确保在第一个字母之后至少有一个字符,您可以将*替换为+,或将{2,}替换为至少多2个字符,或将{2,5}替换为2到5个字符。

您可以尝试:

/^['w., ]+$/

我不知道起始字符有什么要求,如果有的话

Rahul的回答给了我思考的方向,但对于访客来说,也许这也能有所帮助

patternForClasName      =   /^([a-zA-Z0-9 _]+'.)*[a-zA-Z0-9 _]+$/;  
// Allowing valid className which has a format abcsasa.dsd.dsd(the class or a package name can have an underscore or a numerical)
patternForName          =   /^([a-zA-Z0-9 _-]+)$/;
// Allowing alphanumeric + spaces + (_)underscore and a (-)dash
patternForDescription   =   /^([a-zA-Z0-9 _-]+[','.]+)*[a-zA-Z0-9 _-]*$/;
  // Allowing alphanumeric,spaces, (_)underscore, (-)dash, comma, decimal
patternURLFormat        = /(ftp|http|https):'/'/('w+:{0,1}'w*@)?('S+)(:[0-9]+)?('/|'/(['w#!:.?+=&%@!'-'/]))?/;
// For a valid URL