Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL mobile number validation

I have my sql database where i would like to filter out all the valid mobile numbers.

I currently use as follows;

WHERE pn.PhoneNumber LIKE '+[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR pn.PhoneNumber LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR pn.PhoneNumber LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
OR pn.PhoneNumber LIKE '[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]'

However I still receive numbers such as 0000000, 0 ,0000 etc.
Some of the numbers aren't Irish mobiles either as they don't begin with 08.
To fix there if I wanted the beginning of the number to begin with an 087 would I just input [0][8][7] instead of the [0-9]?

like image 867
user3207341 Avatar asked Jul 11 '26 09:07

user3207341


1 Answers

try testing this !

this'll give numbers starting with 087 and mobile(length)=10

select * from table where mobile_number like '087%' and LEN(mobile_number)=10

DEMO

like image 69
vhadalgi Avatar answered Jul 14 '26 00:07

vhadalgi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!