Skip to content

Instantly share code, notes, and snippets.

@pranavcode
Created June 2, 2019 15:16
Show Gist options
  • Save pranavcode/681e8f0197bb69bf37c956d3d3481172 to your computer and use it in GitHub Desktop.
Save pranavcode/681e8f0197bb69bf37c956d3d3481172 to your computer and use it in GitHub Desktop.
Numbers within String input HTML/JavaScript
<html>
<head>
<title>Numbers within String input HTML/JavaScript</title>
<script type="text/javascript">
function qa_calculate_1(inp) {
if (!inp) {
return "Invalid Input: Nothing entered";
}
var re = /[+-]?[0-9]+/g;
var m;
var count=0;
do {
m = re.exec(inp);
if (m) {
if (m[0].length >= 1)
count++;
}
} while(m);
return 'Found ' + count + ' integers';
}
function qa_process() {
var inp = document.getElementById("qa_input_id1").value;
var outp = document.getElementById("qa_output_id1");
outp.innerHTML = qa_calculate_1(inp);
}
</script>
</head>
<body>
<div>
Input string: <input id="qa_input_id1" name="qa_input_1" type="text" autocomplete="off"> <br>
<input value="Process" type="submit" onclick="qa_process()"><br>
Output: <div><pre id="qa_output_id1"></pre></div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment