Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello Team,

I have one query .I have the code as follow:This is one of the Regular Expression which will be Mandatory.
C#
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;
            }

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
Posted

1 solution

1. Insert a if block after the first one to check the existence of substring 'select', using String.Contains Method[^]
2. The current second if block becomes the third one.
3. If not mandatory then just return true for your first if block.

+++++++++++++++++++++++++

Since you insist to use regex, then in point 1, put this code:
C#
var regExpDEOID = /select/i;
if (regExpDEOID.test($('#deoIdSelect').val())) {
    alert("select or SELECT not allowed.");
    return false;
}
 
Share this answer
 
v2
Comments
R Harshal 1-Apr-14 5:36am    
HI Peter,
Thanks For your reply.I dont want to use Contains Method.I want to do in regular Expression only.Please guide.
Thanks
Harshal
Peter Leow 1-Apr-14 6:00am    
see edited solution.
R Harshal 1-Apr-14 7:32am    
Thank You So much.It Works..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900