我想在Tcl中检查输入是否是有效数字。
即:
1.2.0不是。
1.20是。
1e-9是-00.61是。
1.91e-a0不是。
我在网上找不到一个好的答案。
答案 0 :(得分:4)
package Beans;
import java.io.*;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
public class CheckAvailability extends HttpServlet {
private static final long serialVersionUID = -734503860925086969L;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String connectionURL = "jdbc:mysql://localhost:3306/teddb"; // teddb is my database name
Connection connection;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "Sk1994!!");
String uname = request.getParameter("name");
PreparedStatement ps = connection.prepareStatement("select username from users where username=?");
ps.setString(1,uname);
ResultSet rs = ps.executeQuery();
if (!rs.next()) {
out.println("");
}
else{
out.println("Username already in use");
}
out.println();
}
catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException ex) {
out.println("Error ->" + ex.getMessage());
} finally {
out.close();
}
}
}
如果它是有效数字,则返回1,否则返回0.请注意,除非您提供string is double $myNum
选项,否则空字符串将被视为有效数字:
-strict
文档:string