How can I do this?
Let's say the string..
How can I test if the first 2 chars are numbers and then there is a [.] after it?Code:var strString = "12.This is it"
Thanks
Printable View
How can I do this?
Let's say the string..
How can I test if the first 2 chars are numbers and then there is a [.] after it?Code:var strString = "12.This is it"
Thanks
I'd use regular expressions (Javascript in newer browsers has Perl style RegEx syntax, same as VBScript).
Code:if ( /^\d{2}\./.test(strString) ) {
}
I appreciate that. But the strings will not always be the same. It will be like this:Quote:
Originally posted by JoshT
I'd use regular expressions (Javascript in newer browsers has Perl style RegEx syntax, same as VBScript).
Code:if ( /^\d{2}\./.test(strString) ) {
}
1.sdfsddsfsdf
2.dfsdfsdfdsf
3.sdfsdf
etc...
Thanks
Why is the code still finding a match for the [.] when it is not in the string?
Code:
<SCRIPT LANGUAGE=javascript>
<!--
var strString = "12this is it"
if ( /^\d|\d\./.test(strString) ) {
alert(strString)
}
//-->
</SCRIPT>
How can I look for either occurence of 12 or 1 in the string?
Because so far only will find 2 occurences first.
Code:<SCRIPT LANGUAGE=javascript>
<!--
// / beginning and end of what is evaluated
// \d = [0-9]
// \s = space
// \ separator
var strString = "1. this is it"
if ( /^\d|\d\.\s/.test(strString) ) {
alert(strString)
}
//-->
</SCRIPT>
NEver mind , got it!
Code:<SCRIPT LANGUAGE=javascript>
<!--
// / beginning and end of what is evaluated
// \d = [0-9]
// \s = space
// \ separator
var strString = "12. this is it"
if ( /^\d{1,2}\.\s/.test(strString) ) {
alert(strString)
}
//-->
</SCRIPT>
He he, I love it when people answer their own posts ;)