Razal Muhammed
Razal Muhammed

Reputation: 21

Mobile number field should not accept continous 1s, 2s etc

I am trying to make a regexp for mobile number field such that, it would not accept the following type of inputs:

  1. 0000000000
  2. 1111111111
  3. 2222222222

like wise continuous same 10 digits. How to avoid accepting continuous similar ten digits as input for mobile number field?

Upvotes: 0

Views: 453

Answers (2)

Utsav
Utsav

Reputation: 8103

You can use NOT REGEXP_LIKE(MOBILE_NO,'(.)\1{9,}') like below to suppress the unwanted input. But as suggested by Joachim, it is better to avoid it from front end if possible. Check this query and let me know if you get any issue.

WITH TBL(MOBILE_NO) AS
( SELECT '1111111111' FROM DUAL UNION
 SELECT '1234444444' FROM DUAL UNION
 SELECT '2222222222' FROM DUAL
 )
SELECT * FROM TBL
where NOT REGEXP_LIKE(MOBILE_NO,'(\d)\1{9,}')

This will give output as 1234444444 and will skip other mobile_no, where there are 10 consecutive same numbers.

Referred this answer to get this.

Upvotes: 1

user2705585
user2705585

Reputation:

A simple regex solution would be to capture the first digit and check if it's repeated 9 times and then take necessary actions. As you haven't mentioned any other tag I will leave it up to you to apply necessary actions.

Regex: /(\d)\1{9}/g Captures the first digit and if it's repeated 9 times then it matches pattern.

Regex101 Demo

Upvotes: 2

Related Questions