requirements are either positive integers or positive floating point numbers
xixi and are written in a different order
haha xixi
here is the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<title></title>
</head>
<body>
<div class="container">
<span>
:
</span>
<div class="select_wrapper" style="display:inline-block;">
<select name="reg" onchange="change()">
<option value=""></option>
</select>
</div>
<div>
<span class="select_reg"></span>:
<input type="text" class="tagret_str">
<button class="btn" onclick="doReg()"></button>
<p class="result">
</div>
</div>
<script>
var RegExps = {
xixi:/^([1-9]\d*\.\d+)|(0\.\d*[1-9]\d*)|([1-9]\d*)$/ ,
haha:/^([1-9]\d*)|([1-9]\d*\.\d+)|(0\.\d*[1-9]\d*)$/
};
var selectRegs = {
xixi:"",
haha:"haha"
}
function doReg(){
var tagret_str = $(".tagret_str").val();
var reg = RegExps[$("select").val()];
if(reg.test(tagret_str)){
$(".result").text("yes!").css("color","green");
}else{
$(".result").text("No!").css("color","red");
}
}
function change(){
var reg = RegExps[$("select").val()];
$(".select_reg").text(reg);
}
$(function(){
for(var key in selectRegs){
var optionHtml = `<option value="${key}">${selectRegs[key]}</option>`;
$(".select_wrapper").find("select").append(optionHtml);
}
})
</script>
</body>
</html>