Click here to Skip to main content
15,886,740 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Hi all

I'm having a problem in creating a regular expression to validate a field in my PHP system. I have searched for many solutions, but I haven't found a proper one. Can anyone help me to create a regular expression matches the following format. I have tried the below coding, but when validating, it requires to delete a character or whitespace. I would be much obliged if anyone could kindly help me to sort out this issue. Thank you.

Format:

(Numbers) | (English letters).

Ex : 12 | Harindu

What I have tried:

invoice_customer : { validators: {

        notEmpty : { message : 'Customer is required.'},

         regexp: {
             regexp: '\\s\\|\\s',
             message: 'Invalid Format'
         }


    }


},
Posted
Updated 11-Jun-17 21:57pm
v2

1 solution

 
Share this answer
 
Comments
Harindu Karunatillake 12-Jun-17 15:08pm    
Sir, I created the following regular expression using the site, that you mentioned, but it doesn't work for me.
"^[0-9]\s\|\s[a-zA-Z\. \s]+$"
Richard MacCutchan 13-Jun-17 3:36am    
I tried \d+\s\|\s[A-Z][a-z]+ and it worked.

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



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