Reputation: 3935
Hello I need to validate addresses like the following
C/s-2, abc, pqr
C/s/2, abc, pqr
221B Baker Street
101, Baker Street, London, UK
221-B, Baker Street etc
basically looking for standard address types that I can validate using laravel's validation
I have tried following expressions
'address' => 'required|regex:/^(?=.*[0-9])[- ,\/0-9]+$/',
'address' => 'required|regex:/[^a-zA-Z0-9\/-]|[,\/]$/s',
'address' => 'required|regex:/(^([0-9]+ )?[a-zA-Z ]+$)/',
'address' => 'required|regex:/(^[A-Za-z0-9 ]+$)/',
but nothing has worked for me can you please help to get the right regex for such addresses
Thank you :)
Upvotes: 4
Views: 4404
Reputation: 3935
finally got something that is working for me I don't know whether it will work for long or not but presently it is working well.
'address' => 'required|regex:/(^[-0-9A-Za-z.,\/ ]+$)/'
however the previous posted answer is also working well I don't know why he deleted that answer anyway I'm pasting his demo which worked for me
'address' => 'required|regex:/([- ,\/0-9a-zA-Z]+)/',
Upvotes: 8