0
  Hi,
      I have a text field it should allow only Number, only one time 'Q' and 'C'. I created below mentioned code. 

         <input type="text" name="vcno" onkeypress="return blockChars([^0-9-Qq-Cc])">

          function blockChars(Chars){
                   var status = false;       
                   if(Chars.indexOf('\\') != -1)
                   status=true;
                   varKeyCode = getKeyCode() ;
                   if(KeyCode != undefined && isEmptyValue(Chars) ){
                        var g = String.fromCharCode(KeyCode);
                       if(g.match(spChars))
                               return false;
                       else if(g == '+')
                               return false;
                       else if(status && g == '\\')
                               return false;
                       else 
                               return true;
                    }
           }
From this code, my text field allows many No. of times 'Q' and 'C'. Is any regular expression available for my fullfill condition? 
2
Contributors
2
Replies
20
Views
3 Years
Discussion Span
Last Post by sasikrishnasamy
0

So, if I understand right, you want to allow and number of numeric characters but 'Q' or 'C' should only appear once.

([0-9]*)([C-Qc-q]{1})([0-9]*)

However I have some questions:
1. Is the Q or C mandatory or optional
2. Is it one Q and one C
3. Are numeric characters mandatory or optional

0
Thanks for your reply Stbuchok. 
       1.  It is one Q and one C
       2.  Numeric characters or Q and C
 I have some modification in my previous question. I should allow first Q or Numeric characters.

If I type Q first then I should not allow to type Numeric characters.  I should allow typing only C. Q and C appears only one time.  

If I type Numeric characters first then I should not allow to type Q and C. 
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.