Restrict the number

HI
How do i restrict the number of digits for a telephone number?

only the number like that : 77 ### ## ## or 76 ### ## ## or 70 ### ## ## or 33 ### ## ## teh interview can enter

please help urgent

1 Like

It seems that you are going for a text question with a pre-determined pattern. Assume this variable is called β€œtelephone_number”:

  1. I’d also use this approach in this scenario.
    But use pattern: ## ### ## ## to allow only numeric characters.

  2. To check the correct value at the first two digits, and if it is indeed just about those 4 digit combinations, the simplest approach that comes to my mind:
    2a) Get the value of the first two digits through
    telephone_number.Left(2)
    2b) Validate that it is only any of your desired values:
    telephone_number.Left(2).Contains("70") || telephone_number.Left(2).Contains("76") || telephone_number.Left(2).Contains("77") || telephone_number.Left(2).Contains("30")

You can also use self.Left(2).Contains("77")... if you are using it as a validation condition at variable β€œtelephone_number”.

Best,
Peter

1 Like

Thank you so much it’s done and it works :wink:

1 Like

It’s easier to search the actual input in the whitelist:

"33 70 76 77".Contains(self.Left(2))

Another approach could be to ask for the operator first (e.g. ATT, T-Mobile, Vodafone, …) then accept only codes specific to a particular operator (not much advantage if they use multiple codes plus the respondent may not necessarily know the operator).

Best, Sergiy

4 Likes