What can we do to get exact 10 characters, neither more nor less?

hi, @kal_lam, I am also trying to do the same thing of restricting the users from inputting mobile numbers not more than 10 digits. I have used the expression “regex(., ‘^[0-9]{10}$’)”, and it worked for mobile numbers not more than 10. But it is taking 9 digits also. What can we do to get exact 10 characters, neither more nor less. Please advise. Looking forward to your reply.

Welcome to the community, @mavim! Would you mind sharing the relevant part of your XLSForm with the community so that the community could test it out for you?

@mavim Hi,
This regex exactly get 10 digit, digits can’t start with 0, it must start a digit between 1-9, and after that you can use 0.
regex(., ‘^[1-9][0-9]{9}$’)

if you would like to start with 0
regex(., ‘^[0-9][0-9]{9}$’)

1 Like

Your initial regex should work for exactly 10 digits - with thr probkem that you cojld start with anx digit. Be aware that this is a constraint which is only evaluated when you leave the field, but not during editing.

You can look at the Help Center article and use the search function of this forum to find more hints

1 Like

Hi, @ismanburcu, I tried the solution as suggested by you. It was perfect solution for my query. Thank you so much.

2 Likes