0

Hi i want to use regular expression to check if a string is in the format :
1+2 or +12 or 12+ or 1-2 or -12 or 12-. CAn someone help?

2
Contributors
12
Replies
14
Views
5 Years
Discussion Span
Last Post by pritaeas
0
var num=(string.slice(0,2))
    if (/^\d+$/.test(num))
        document.write ("true");
0

i want to check if there is a number in 1st and 2nd position and an operator in the third. That is 32+. then it returns true

0

I am writing it like this n it's not working! why this?

var x=/[-+]\d{2}|\d[-+]\d|\d{2}[-+]/;

    if (string.test(x))
    {
        document.write("true");

    }

Edited by techyworld

0

I am writing it like this n it's not working! why this?

var reg=/[-+]\d{2}|\d[-+]\d|\d{2}[-+]/;

    if (string.test(reg))
    {
        document.write("true");

    }
0
var subject = '+12';
if (subject.match(/[\-+]\d{2}|\d[\-+]\d|\d{2}[\-+]\/[\-+]\d{2}|\d[\-+]\d|\d{2}[\-+]/)) {
    alert('Successful match');
} 
else {
    alert('Match attempt failed');
}
0

1+2=3
regular expresion /\d[-+]\d\=\d/ ,Is the regular expression good for the above statement??

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.