简体   繁体   中英

how to validate particular format using javascript?

I want to allow number only in following format and check validation using javascript.

BEnnnn.nnn.nnn (where n is a number)

How can I do it?

Edited for a full example :

BEnnnn.nnn.nnn => where n is number , then :

var testString = 'BE5555.333.333';
var pattern = new RegExp('^BE\\d{4}\\.\\d{3}\\.\\d{3}$','gm');
alert(pattern.test(testString));

or

var testString = 'BE5555.333.333';
var pattern = /^BE\d{4}\.\d{3}\.\d{3}$/gm;
alert(pattern.test(testString));

Working sample : http://jsfiddle.net/rvHtr/

Recommended lecture BTW :

Regex in a nutshell

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