Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 indian mobile number validation

Author  Topic 

rammohan
Posting Yak Master

212 Posts

Posted - 2008-10-21 : 09:03:55
hi can anyone give me a function to validate indian mobile number ie it shud not exceed 14 chars and also it shud not be less than 10 digits n it can accept formats like this

(+91)-973132423

9731789889

+91-9767767645

One can never consent to creep,when one feels an impulse to soar
RAMMOHAN

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-21 : 09:06:08
Where do you want to get data from?
If you use front end application, do this validation there


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rammohan
Posting Yak Master

212 Posts

Posted - 2008-10-21 : 09:07:34
i am try to validate it at back end. i need to write a fucntion which will evaluates string based on this criteria

One can never consent to creep,when one feels an impulse to soar
RAMMOHAN

Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-10-21 : 09:10:57
I disagree. Use a constraint using LIKE and any other string functions.
You should never assume your client can reliably validate or clean up your data.
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-10-21 : 09:22:47
We have a bulk sms gateway that sends sms to numbers and they are all validate at the backend. We use a function to validate each country format passed to it.

Funny, we got some tips from Madhivanan's blog on integer validation, the rest validates the length, starting character and network code
Go to Top of Page

rammohan
Posting Yak Master

212 Posts

Posted - 2008-10-21 : 09:55:14
Thanks for u r help, but i need to write a UDF for it

One can never consent to creep,when one feels an impulse to soar
RAMMOHAN

Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-10-21 : 09:58:35
well you are doing it wrong, but you can still write a function using LIKE and stuff. If you write the UDF you can and should add it as a constraint. Checkout the string functions in BOL. It's pretty straightforward.
Go to Top of Page

rammohan
Posting Yak Master

212 Posts

Posted - 2008-10-22 : 02:45:26
please, i want an UDF for this asap

One can never consent to creep,when one feels an impulse to soar
RAMMOHAN

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-22 : 03:51:22
quote:
Originally posted by rammohan

(+91)-973132423
9731789889
+91-9767767645
What is the correct way to format these three samples?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

rammohan
Posting Yak Master

212 Posts

Posted - 2008-10-22 : 06:11:23
it has to accept any of these three formats only

One can never consent to creep,when one feels an impulse to soar
RAMMOHAN

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-22 : 07:59:48
One method is


declare @data table(phno varchar(20))
insert into @data
select '(+91)-9731324283' union all
select '9731789889' union all
select '97(31)-789889' union all
select '91-9731789889' union all
select '(91)9731789889' union all
select '+9731789889' union all
select '+91-9767767645'

select phno from @data
where phno 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]' or
phno like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' or
phno 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]'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -