I need to match a string like 2431-72367, i.e., a string with at least one number before and after the dash and only one dash.
I need to check it in JavaScript. Can anyone give me the regex and explain it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
/^\d+-\d+$/will work.^signals the begin of the string.\d+means one or more digits.$signals the end of the string.As a result,
/^\d+-\d+$/.test("2431-72367")returns true.