Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use validate with regex_match[] #1084

Closed
HieuPT7 opened this issue Jun 25, 2018 · 6 comments
Closed

Can't use validate with regex_match[] #1084

HieuPT7 opened this issue Jun 25, 2018 · 6 comments

Comments

@HieuPT7
Copy link
Contributor

HieuPT7 commented Jun 25, 2018

Hi
I use pattern = "/^(01[2689]|09)[0-9]{8}$/" , regex phone number of Viet Nam but it not work

https://bcit-ci.github.io/CodeIgniter4/libraries/validation.html
My Code

$validate->setRules([
            'phone' => [
                'label'  => 'Phone Number',
                'rules'  => 'regex_match[/^(01[2689]|09)[0-9]{8}$/]'
            ]
        ]);

Thanks !!

@lonnieezell
Copy link
Member

Did it crash, or just not give the results you intended? If it crashed, what error did it throw?

Can you provide a phone number (fake preferred) that it should match?

@HieuPT7
Copy link
Contributor Author

HieuPT7 commented Jun 26, 2018

An error occured by the character ] in regex pattern.

i tested print_r($pattern) in function regex_match on file system/Validation/FormatRules.php then it not match with input pattern.

Phone number: https://github.com/datnq/Vietnamese-mobile-carrier

Thanks

@jinmarcus
Copy link

jinmarcus commented Jun 29, 2018

'rules' => 'required|min_length[2]|max_length[20]|regex_match[/^(01[2689]|09)[0-9]{8}$/]'
in regex_match
If the ' | ' symbol is contained, it will be truncated

@lonnieezell

@jinmarcus
Copy link

jinmarcus commented Jun 29, 2018

I think it should be designed this way
[
'phone' => [
'label' => 'Phone Number',
'rules' => [
required => true,
regex_match => '/^(01[2689]|09)[0-9]{8}$/'
]
]
]

This is more reasonable

@lonnieezell

@lonnieezell
Copy link
Member

@jinmarcus did this work in CI3? Trying to figure out if I broke something in the conversion.

@andreifurrnica
Copy link
Contributor

@lonnieezell it didn't. i just tested it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants