/**
* Created by Administrator on 2019/10/12.
*/
function reg(eleID, rule){
var inputValue = document.getElementById(eleID).value;
var result = rule.test(inputValue.trim());
if (result && inputValue != ""){
document.getElementById(eleID+"Reg").innerHTML = "√";
document.getElementById(eleID+"Reg").style.color = "green";
}else {
document.getElementById(eleID+"Reg").innerHTML = "×";
document.getElementById(eleID+"Reg").style.color = "red";
}
}
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">