javascript phone validataion
javascript phone validataion
<?php
//include the DB connection
include("includes/config.php");
//include the header
include("includes/header.php");
?>
<?php
//checks if the form was submitted
if(isset($_POST['submit']))
{
//get form values when submitted
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$password=$_POST['password'];
$subject=$_POST['subject'];
$target_dir = "uploads/";
$target_file = $target_dir . time() . basename($_FILES["file"]["name"]);
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file))
{
mysql_query("INSERT INTO `login`(`name`,`email`,`phone`,`password`,`file`,`subject`)VALUES('$name','$email','$phone','$password',
'$target_file','$subject')");
echo "The file ". basename( $_FILES["file"]["name"]). " has been uploaded.";
}
else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
<div class="form">
<form action="" method="post" name="registration" enctype="multipart/form-data" onSubmit="return formValidation();">
<table width="500" border="1" cellspacing="0" cellpadding="0" class="table">
<tr>
<td>Name</td>
<td><input name="name" type="text" class="input" placeholder="Please Enter Your Name" value="<?php //echo $userName ;?>" /></td>
</tr>
<tr>
<td>Email</td>
<td><input name="email" type="email" class="input" placeholder="Please Enter Your Email ID "value=" <?php //echo $userEmail ;?>" /></td>
</tr>
<tr>
<td>Phone</td>
<td><input name="phone" type="text" class="input" placeholder="Please Enter Your Phone Number" value="<?php //echo $userPhone;?>" /></td>
</tr>
<tr>
<td>Password</td>
<td><input name="password" type="password" class="input" value="" /></td>
</tr>
<tr>
<td>Upload file</td>
<td><input name="file" type="file" class="input" value="" </td>
</tr>
<tr>
<td>Subject</td>
<td><textarea name="subject" cols="" rows="" class="input" placeholder="Please Enter Your Query "/> <?php //echo $userSubject;?></textarea></td>
</tr>
<tr>
<td></td>
<td><input name="submit" type="submit" value="Submit" /></td>
</tr>
</table>
</form>
</div>
<?php
//include the footer
include("includes/footer.php");
?>
<script type="text/javascript">
function formValidation()
{
var uname = document.registration.name;
var uphone= document.registration.phone;
if(allLetter(uname))
{
if(phonenumber(uphone))
{
}
}
return false;
}
function allLetter(uname)
{
var letters = /^[A-Za-z]+$/;
if(uname.value.match(letters))
{
return true;
}
else
{
alert('Username must have alphabet characters only');
uname.focus();
return false;
}
}
function phonenumber(inputtxt)
{
var phoneno = /^'d{10}$/;
if((inputtxt.value.match(phoneno))
{
return true;
}
else
{
alert("message");
return false;
}
}
</script>
对于用户名,验证代码有效,但对于电话验证它不起作用,我想要电话验证空字段检查和格式检查以及电子邮件检查.帮助我,因为我是 JavaScript 的新手
试试这段代码。
function formValidation()
{
var phone=document.forms["registration"]["phone"].value;
var phone_num = /^'d{10}$/;
if (phone=="")
{
alert("enter your phone number");
return false;
}
else if(phone)
{
if(!phone_num.test(phone))
{
alert("Not a valid Phone Number");
return false;
}
}
var email = document.forms["registration"]["email"].value;
if (email=="")
{
alert("enter your email id");
return false;
}
var atpos = email.indexOf("@");
var dotpos = email.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length)
{
alert("Not a valid e-mail address");
return false;
}
}
您的手机功能中有一个额外的typo
(
:
尝试:
if(inputtxt.value.match(phoneno))
而不是if((inputtxt.value.match(phoneno))
PS:
提示在使用JS
时查看和使用控制台工具
相关文章:
- 在Windows Phone应用程序中激活javaScript
- 如何使用SAML和C#调试Windows Phone 8.1应用程序的Javascript代码
- 如何在Windows Phone 8.1应用程序中在C#和Javascript之间传递数据或通信
- IntelXDK Cordova iframe Phone Call
- 如何在 Windows Phone 中重定向页面
- onclick事件不适用于phone gap android
- 如何使用Windows Phone在IE上禁用上下文菜单(保存和共享照片)
- 如何从 HTML 或 Javascript for Windows Phone 访问图像文件
- WinJs 复制到 Windows Phone 的剪贴板
- IE11(Windows Phone 8.1)不感应(显示尺寸)屏幕旋转
- IBM Mobile First Platform (6.3) - Windows Phone 8 environmen
- javascript phone validataion
- window.open()在使用phone gap的iOS应用程序上不起作用
- Windows Phone浏览器控件执行JS函数来替换src属性
- 通过Javascript处理Windows Phone 7后退按钮
- JS OAuth 2.0 on Windows Phone 8.1
- Windows phone 8和phonegap 2.7.0,HTML页面和Xaml之间的导航以及返回
- Angular http在Phone gap中返回错误,但在浏览器中成功
- 使用WinJs构建的Pivot的幻灯片事件没有'不适用于windows Phone
- 本地文件上的Windows Phone 8 jQuery.ajax失败