如何使用正则表达式强制性和非强制性。 [英] How to use Regular Expression For Mandatory and for Not Mandatory.

查看:119
本文介绍了如何使用正则表达式强制性和非强制性。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好团队,



我有一个查询。我的代码如下:这是一个必须的正则表达式。

Hello Team,

I have one query .I have the code as follow:This is one of the Regular Expression which will be Mandatory.

if ($('#deoIdSelect').val().replace(' ', '') == '') {
                alert('Enter DEOID.');
                return false;
            }
            var regExpDEOID = /^[a-zA-Z0-9]*$/;
            if (!regExpDEOID.test($('#deoIdSelect').val())) {
                alert("DEOID Must Be Number and Alphabets Only.");
                return false;
            }



在上面的代码中,我写了正常表达,它正在工作。但是如果在deoIdSelect中

textbox我有像'select'和'DEO01'这样的值,我不想在deoIDSelect文本框中'select',如果它存在,它应该给出警告(选择值而不是'select')。请指导我如何修改我的常规表达。



其次,如果deoIDSelect不是强制性的那么将是我的正则表达式。



谢谢

Harshal


As in the Above Code ,i wrote the Regular expression which is working .But if in deoIdSelect
textbox i have the value like 'select' and 'DEO01',I dont want 'select' in deoIDSelect textbox ,if it is present ,it should give the alert(select the value instead of 'select').Please guide me how to modify my Regular Expression.

Secondly,If deoIDSelect is not Mandatory then what will be my Regular Expression.

Thanks
Harshal

推荐答案

' #deoIdSelect')。val()。replace(' '' ')== ' ){
alert(' 输入DE OID)。
return false ;
}
var regExpDEOID = / ^ [a-zA-Z0-9] *
('#deoIdSelect').val().replace(' ', '') == '') { alert('Enter DEOID.'); return false; } var regExpDEOID = /^[a-zA-Z0-9]*


/ ;
if (!regExpDEOID.test(
/; if (!regExpDEOID.test(


' #deoIdSelect')。val())){
alert( DEOID必须是数字和字母。);
return false ;
}
('#deoIdSelect').val())) { alert("DEOID Must Be Number and Alphabets Only."); return false; }



在上面的代码中,我写了正常表达,它正在工作。但是如果在deoIdSelect中

textbox我有像'select'和'DEO01'这样的值,我不想在deoIDSelect文本框中'select',如果它存在,它应该给出警告(选择值而不是'select')。请指导我如何修改我的常规表达。



其次,如果deoIDSelect不是强制性的那么将是我的正则表达式。



谢谢

Harshal


As in the Above Code ,i wrote the Regular expression which is working .But if in deoIdSelect
textbox i have the value like 'select' and 'DEO01',I dont want 'select' in deoIDSelect textbox ,if it is present ,it should give the alert(select the value instead of 'select').Please guide me how to modify my Regular Expression.

Secondly,If deoIDSelect is not Mandatory then what will be my Regular Expression.

Thanks
Harshal


这篇关于如何使用正则表达式强制性和非强制性。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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