The js implementation extracts Numbers from strings

  • 2020-03-26 23:03:52
  • OfStack

< ! PUBLIC DOCTYPE HTML "- / / / / W3C DTD XHTML 1.0 Transitional / / EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< HTML XMLNS = "http://www.w3.org/1999/xhtml" >
< Head>
< Meta HTTP - equiv = "content-type" Content = "text/HTML. Charset = gb2312 "/ >
< Title> Js implementation extracts Numbers from strings < / title>
< Script language = "javascript" type = "text/javascript" >
The function getNum (text) {
Var value = text. Replace (/ [^ 0-9] / ig, "");
Alert (value);
}
< / script>
< / head>


< Body>
< Input type = "text" id = "btn_getNum" / >
< Input type="button" value=" get the number "onclick="getNum(btn_getnum.value);" / >
< / body>
< / html>


Related articles: