1

A field that needs to be inputted must be in the exact form 6 numbers . four numbers

so for example 123456.0001

Any help greatly appreciated.

1
  • RegExp at MDN. Commented Jul 8, 2014 at 9:18

3 Answers 3

1

You can use this regular expression:

\d{6}\.\d{4}

For example:

/\d{6}\.\d{4}/.test("123456.1234");
=> true
/\d{6}\.\d{4}/.test("1234.123456");
=> false
Sign up to request clarification or add additional context in comments.

Comments

0

Try the below regex,

^[0-9]{6}\.[0-9]{4}$

You need to specify the start ^ and the end$.

EXplanation:

  • ^ Means that we are at the beginning of the line.
  • [0-9]{6} Matches a 6 digit number.
  • \. Matches a literal dot.
  • [0-9]{4} Matches a 4 digit number.
  • $ End of the line.

Comments

0

Use this:

if (/^\d{4}\.\d{6}$/m.test(yourString)) {
    // It matches!
} else {
    // Nah, no match...
}

Explanation

  • The ^ anchor asserts that we are at the beginning of the string
  • \d{4} matches four ASCII digits
  • . matches a period
  • \d{6} matches six ASCII digits
  • The $ anchor asserts that we are at the end of the string

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.