正则表达式javascript [英] Regex expression javascript

查看:101
本文介绍了正则表达式javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我需要一个正则表达式只允许文本框中的某些文本

Hello I need a regex expression to allow only certain text in a textbox

 10 numbers: 0 to 9
 26 letters: A to Z (upper cases)
 10 non-alphanumeric characters: - @ # $ % ( ) \ / . (dot)





第5个字符应为*



示例

TLDZ * BB01S6N

22(O * AVB124C



我的尝试:



.keypress(函数(e){



var validChar = String.fromCharCode(e .which).search(/ ^ [0-9A-Z] $ /)=== 0;



if(!validChar ||((e.which) != 46 || $(this).val()。indexOf('*')!= -5)&&

(e.which< 35 || e.which> ; 37)&&

(e.which< 40 || e.which> 42)&&

(e.which< 45 || e.which> 57)&&

(e.which< 64 || e.which> 90)&&

( e.which == 92))){

e.preventDefault();



}



The 5th Character should be an *

example
TLDZ*BB01S6N
22(O*AVB124C

What I have tried:

.keypress( function ( e ) {

var validChar = String.fromCharCode(e.which).search(/^[0-9A-Z]$/) === 0;

if (!validChar || ( (e.which != 46 || $(this).val().indexOf('*') != -5) &&
(e.which < 35 || e.which > 37) &&
(e.which < 40 || e.which > 42) &&
(e.which < 45 || e.which > 57) &&
(e.which < 64 || e.which > 90) &&
(e.which == 92) )) {
e.preventDefault();

}

推荐答案

%()\ /。(点)





第五个字符应为*



示例

TLDZ * BB01S6N

22(O * AVB124C



什么我试过了:



.keypress(function(e){



var validChar = String.fromCharCode(e.which).search(/ ^ [0-9A-Z]



The 5th Character should be an *

example
TLDZ*BB01S6N
22(O*AVB124C

What I have tried:

.keypress( function ( e ) {

var validChar = String.fromCharCode(e.which).search(/^[0-9A-Z]


/)=== 0;



if(!validChar ||((e.which!= 46 ||
/) === 0;

if (!validChar || ( (e.which != 46 ||


(this).val() .indexOf('*')!= -5)&&

(e.which< 35 || e.which> 37)&&

(e.which< 40 || e.which> 42)&&

(e.which< 45 || e.which> 57)&&

(e.which< 64 || e.which> 90)&&

(e.which == 92))){

e.preventDefault();



}
(this).val().indexOf('*') != -5) &&
(e.which < 35 || e.which > 37) &&
(e.which < 40 || e.which > 42) &&
(e.which < 45 || e.which > 57) &&
(e.which < 64 || e.which > 90) &&
(e.which == 92) )) {
e.preventDefault();

}


这篇关于正则表达式javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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