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? 
Member Avatar for stbuchok

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

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. 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.