doupu1949 2013-02-07 16:03
浏览 20

指定字段中的整数数

I'm doing a sign up form page where I should put also a "telephone" input but i need the telephone field to be 8 digits!!! if a user put a number more or less than 8 digits the signup form tells him an error.

it should be like this i think... after connecting to DB

  $telephone=$_POST['telephone'];
  ... 
  .... 
  if(empty($telephone)){ // **i think i should write smth here???**
  echo  "phone number not set, and should be 8 digits!!" ;
  }
  else{

  /* Now we will write a query to insert user details into database */
  $insert_user=mysql_query("INSERT INTO login (telephone) VALUES ('$telephone')");

i appreciate any help :) thank you

  • 写回答

3条回答 默认 最新

  • douju1365 2013-02-07 16:07
    关注

    First of all: not all telephone numbers are exactly 8 digits. So you shouldn't force it that strictly.

    For sensible validation of phone numbers, there are a number of good answers in this thread: A comprehensive regex for phone number validation

    On a personal note, you really shouldn't use more than one exclamation mark in production code. Reading a '!!' is somewhat... upsetting... to users and other developers alike.

    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答