正则表达式仅允许使用字母,数字,空格,逗号,句号? [英] Regex for only allowing letters, numbers, space, commas, periods?

查看:528
本文介绍了正则表达式仅允许使用字母,数字,空格,逗号,句号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对正则表达式一无所知,因为它对我来说很复杂.我正在使用一个基于正则表达式限制用户输入的程序.我目前正在使用仅允许用户输入的正则表达式:

A-Z and a-z
0-9
.
,
!
?

基本上,典型段落或网络文章中的所有内容.

程序声明输入一个正则表达式,该正则表达式必须使输入的文本匹配(通过preg_match进行评估,并使用s和i标志),该文本才有效."

我已经尝试过此正则表达式,但没有成功,目前我正在寻找其他人可以尝试.

 '/^[a-zA-Z0-9,.!? ]*$/'

它应该允许一个简单的句子,例如

我叫约翰!我喜欢吃苹果,橘子和葡萄.你愿意和我一起吃饭吗?

解决方案

Debuggex示例

^[a-zA-Z0-9,.!? ]*$

是正则表达式,它可以正常工作,请参见示例网站以测试正则表达式.

I am clueless with regex as it is complicated for me. I am working with a program that limits input from users based on a regex. I am currently after a regex that will only let the user input:

A-Z and a-z
0-9
.
,
!
?

So basically anything in a typical paragraph or web article.

The program states "Enter a regular expression which entered text must match (evaluated with preg_match, using s and i flags) for it to be valid."

I have tried this regex with no success and I am currently searching for others to try.

 '/^[a-zA-Z0-9,.!? ]*$/'

It should allow a simple sentence such as

"HI my name is John! I like to eat apples, oranges, and grapes. Will you eat with me?

解决方案

Debuggex example

^[a-zA-Z0-9,.!? ]*$

is what the regex is, it works, see example website to test regex.

这篇关于正则表达式仅允许使用字母,数字,空格,逗号,句号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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