带点验证的字母数字文本 [英] Alphanumeric text with dot validation

查看:80
本文介绍了带点验证的字母数字文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用户名字段中有一个Java代码要求,我必须只允许使用字母数字和点,如下所示。



验证应检查以下条件



abc.xyz.jk应该被允许

xyz..kk ..不应该被允许(不允许连续点)

只允许....不允许(不允许连续点)

仅限。不应该被允许



我尝试用一​​种带有正则表达式的方法验证这一点,但它也允许多个点。



我尝试了什么:



我尝试了一种方法,但我只允许使用点数

I have a Java code requirement in a username field where I have to allow only Alphanumeric and dots as below.

Validation should check below conditions

abc.xyz.jk should be allowed
xyz..kk.. should not be allowed (Consecutive dots shouldn't be allowed)
Only .... should not be allowed (Consecutive dots shouldn't be allowed)
Only . should not be allowed

I've tried validating this with a method with regex, but it allows more than one dot as well.

What I have tried:

I have tried a method but i allows only dots as well

推荐答案

尝试使用正则表达式:
^(\w\.?)+


应该这样做。


RegEx就是你要找的。



只是一些有趣的链接来帮助建设和调试RegEx。

以下是RegEx文档的链接:

perlre - perldoc.perl.org [ ^ ]

以下是帮助构建RegEx并调试它们的工具的链接:

.NET Regex Tester - Regex Storm [ ^ ]

Expresso正则表达式工具 [ ^ ]

RegExr:Learn,Build,&测试RegEx [ ^ ]

在线正则表达式测试器和调试器:PHP,PCRE,Python,Golang和JavaScript [ ^ ]

这个显示RegEx是一个很好的图表,它非常有助于理解RegEx的作用: Debuggex:在线可视正则表达式测试器。 JavaScript,Python和PCRE。 [ ^ ]

此网站还在一个漂亮的图表中显示正则表达式,但无法测试与RegEx匹配的内容: Regexper [ ^ ]
RegEx is what you looking for.

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx: Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx: Regexper[^]


这篇关于带点验证的字母数字文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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