I need to write a regex for a text-box field validation on the JSF page. I need this field to be an empty, or contains a sequence of [a-z]1[a-z]54. How can I do that?
            Asked
            
        
        
            Active
            
        
            Viewed 115 times
        
    -5
            
            
         
    
    
        St.Antario
        
- 26,175
- 41
- 130
- 318
- 
                    what's stopping you? – Mitch Wheat Dec 26 '14 at 09:08
- 
                    @MitchWheat I don't how to write a condition in regex – St.Antario Dec 26 '14 at 09:08
- 
                    2time to learn perhaps? – Mitch Wheat Dec 26 '14 at 09:08
- 
                    You don't need to do a regex conditional. Just disjunct the entire regex match with `string.length == 0` – quantumtremor Dec 26 '14 at 09:09
- 
                    @MitchWheat I mean, if the string doesn't match [a-z]1[a-z]54 then it shall match an empty string. – St.Antario Dec 26 '14 at 09:09
- 
                    @quantumtremor I know, but unfortunately I need to do it via regex. Is it possible – St.Antario Dec 26 '14 at 09:10
- 
                    possible duplicate of [Regex empty string or email](http://stackoverflow.com/questions/5063977/regex-empty-string-or-email) – Max Leske Dec 26 '14 at 10:06
- 
                    2why the vote to close? it's not asking for an off-site resource, there are 3 answers here all basically equivalent – Jasen Dec 26 '14 at 10:41
3 Answers
4
            
            
        You could try this also,
^([a-z]1[a-z]54)?$
? after the capturing group would make the whole capturing group as an optional one.
 
    
    
        Avinash Raj
        
- 172,303
- 28
- 230
- 274
 
     
    