正则表达式javascript [英] Regex expression 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屋!