简体   繁体   中英

Regular Expression allow characters and 1 dot only between

I want a regular expression which only allows az characters and 1 dot only between characters, not in the beginning or end of the string, here is what I've got:

var myRegexp = /^[a-zA-Z]*(\.{1}[a-zA-Z]*)?$/;

But it also allows the dot to be the first or the last character, how could I disallow dot in beginning or at the end of string?

The above code works in JS, how about the same regular expression in PHP with preg_match()?

Thanks in advance

The * means 0-many. If you use a + then this will force at least 1 character to appear before and after the dot. ie

var myRegexp = /^[a-zA-Z]+(\.{1}[a-zA-Z]+)?$/;

尝试这个

var myRegexp = /^[a-z]+(\.[a-z]+)?$/i;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM