求Email验证和密码验证的正则表达式

yangcl 2003-12-09 10:42:35
Email验证为普通的验证
密码么,要求只能是数字和字母

以前没用过正则表达式
劳烦各位能不能把
正则表达室的程序使用代码贴出来


谢谢!
...全文
366 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangcl 2003-12-09
  • 打赏
  • 举报
回复
各位,能不能给我一段示例代码呢?谢拉
ishero 2003-12-09
  • 打赏
  • 举报
回复
Regex(REGEXP_IS_VALID_EMAIL)).IsMatch(validate)

validate:是你要验证的字符串

或者网页上添加RequiredFieldValidator控件,设置该控件的ControlToValidator属性为该验证字符串输入框的ID,设置ErrorMessge属性为你要显示的信息,设置InitalValue为该正则表达式,OK
NetFire 2003-12-09
  • 打赏
  • 举报
回复
email 的

<asp:RegularExpressionValidator id="RegularExpressionValidator4" runat="server" ErrorMessage="电子信箱输入有错误" Display="Dynamic"
Font-Size="9pt" ControlToValidate="email" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>


密码的

<asp:RegularExpressionValidator id="RegularExpressionValidator3" runat="server" ErrorMessage="用户密码有不合法字符" Font-Size="9pt"
ControlToValidate="pass2" ValidationExpression="^[^<']*"></asp:RegularExpressionValidator>
ishero 2003-12-09
  • 打赏
  • 举报
回复
密码的:\w{1,n}
n是密码的长度
ishero 2003-12-09
  • 打赏
  • 举报
回复
Email: \w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w

yangcl 2003-12-09
  • 打赏
  • 举报
回复
to icyer() :
谢谢呀

这是Email验证的吧
可是
"^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$"该怎么用呢?
教教俺吧
可别怪我是白痴,呵呵...
acewang 2003-12-09
  • 打赏
  • 举报
回复
http://www.regexlib.com/Search.aspx
在这输入Email关键字,能找到你想要的验证代码
icyer 2003-12-09
  • 打赏
  • 举报
回复
"^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$"

try it
wenmingxing516 2003-12-09
  • 打赏
  • 举报
回复
<td align="right">Email:</td>
<td><asp:TextBox runat="server" size="40" id="Email" />
<asp:RequiredFieldValidator runat="server" Text="(必要栏位)"
ControlToValidate="Email" EnableClientScript="False"
Display="Dynamic" />
<asp:RegularExpressionValidator runat="server"
ControlToValidate="Email" Text="(Email 应含有 @ 符号)"
ValidationExpression=".{1,}@.{3,}"
EnableClientScript="False" Display="Dynamic"/>
</td>
acewang 2003-12-09
  • 打赏
  • 举报
回复
这是个简单例子:
<%@ Page Language="C#" %>

<html>
<head>
<script runat="server">

void ValidateBtn_Click(Object sender, EventArgs e)
{
if (Page.IsValid)
{
lblOutput.Text = "Page is Valid!";
}
else
{
lblOutput.Text = "Page is InValid!";
}
}

</script>

</head>
<body>

<h3>RegularExpressionValidator Sample</h3>
<p>

<form runat="server">

<table bgcolor="#eeeeee" cellpadding="10">
<tr valign="top">
<td colspan="3">
<asp:Label id="lblOutput"
Text="Enter a 5 digit zip code"
Font-Name="Verdana"
Font-Size="10pt"
runat="server"/>
</td>
</tr>

<tr>
<td colspan="3">
<font <b>Personal Information</b>
</td>
</tr>
<tr>
<td align="right">
Zip Code:
</td>
<td>
<asp:TextBox id="TextBox1"
runat="server"/>
</td>
<td>
<asp:RegularExpressionValidator id="RegularExpressionValidator1"
ControlToValidate="TextBox1"
ValidationExpression="------正则表达式放这--------"
Display="Static"
EnableClientScript="false"
ErrorMessage="...错误提示"
runat="server"/>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button text="Validate"
OnClick="ValidateBtn_Click"
runat="server"/>
</td>
<td></td>
</tr>
</table>

</form>

</body>
</html>
yangcl 2003-12-09
  • 打赏
  • 举报
回复
up

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧