Hi all,I am trying for validation using regular expression for Indian mobile number.
Simply i have tried for"^[8,9]{1}[0-9]{9}$" and some others also
but it is not working.
I want regular expression for:
10 digit mobile number
starts with 8 or 9

Dani AI

Generated

asked for client-side validation of a 10-digit Indian mobile number that begins with 8 or 9. confirmed the pattern works in a tester, and correctly noted that anchors enforce an exact match. If the expression behaves differently inside your app, the pattern itself is often fine; the usual issues are how the input is prepared or how the regex is applied.

Common causes to check: trim the value before testing (use trim()), ensure the value is a string and not a numeric type (which can drop leading characters), and strip any optional prefixes such as +91 or a leading 0 before validating. Watch for invisible characters (nonbreaking space or zero‑width) and formatted input (spaces/hyphens). If using an HTML5 pattern on an <input>, note the element expects the whole value to match; see MDN: input pattern attribute. When testing in code, use the RegExp methods designed for boolean checks (for example, test() in JavaScript) so you get an immediate true/false result.

Also consider scope: Indian mobile allocations now include other leading digits (mobile numbers may begin with 6, 7, 8, or 9), so restricting validation to only 8 or 9 can reject valid numbers today; see Telephone numbers in India. For production use, normalize input (remove prefixes/formatting), then validate, and always repeat validation on the server side.

Recommended Answers

All 2 Replies

Hi all,I am trying for validation using regular expression for Indian mobile number.
Simply i have tried for"^[8,9]{1}[0-9]{9}$" and some others also
but it is not working.
I want regular expression for:
10 digit mobile number
starts with 8 or 9

Based on that regexp, you must be sure that there are no characters before 8 or 9 AND no characters after the last digit, because you're using the ^ and $. Maybe try pasting the source code to your application to see what you're trying to do with regexp, to try to help you further.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.