need code for search another character
Posted
by klox
on Stack Overflow
See other posts from Stack Overflow
or by klox
Published on 2010-06-09T03:15:54Z
Indexed on
2010/06/09
3:22 UTC
Read the original article
Hit count: 286
JavaScript
|regex
hi,all..i have this code:
var str = "KD-R435MUN2D";
var hasUD;
var patt1 = str.match(/U/gi);
var patt2 = str.match(/D/gi);
if (patt1 && patt2) {
hasUD = 'UD';
} else {
hasUD = false;
}
document.write(hasUD);
how to modify this code if i want search JD
from var str="KD-S35JWD"
..i try this but doesn't work:
<script type="text/javascript">
var str = "KD-R435jwd";
var hasUD;
var hasJD;
var patt1 = str.match(/U/gi);
var patt2 = str.match(/J/gi);
var patt3 = str.match(/D/gi);
if (patt1 && patt3) {
hasUD = 'UD';
document.write(hasUD);
} elseif (patt2 && patt3) {
hasJD = 'JD';
document.write(hasJD);
}
</script>
© Stack Overflow or respective owner