电子邮件和电话号码的CSV列验证 [英] CSV column validation for Email and phone number

查看:98
本文介绍了电子邮件和电话号码的CSV列验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在上载有电话号码和电子邮件的csv文件我想验证它们是否是有效的密码栏或电话号码栏



先谢谢你

I am Uploading csv file having phone number and email i want to validate whether they are valid password column or phone number column

Thanks in Advance

推荐答案

您可以使用正则表达式进行验证。

这是一个很好的起点:Regular-Expressions.info:正则表达式教程 [ ^ ]

也在这里:正则表达式语言 - 快速参考 [ ^ ]



更专门用于验证电子邮件,您可以从这里开始:如何查找或验证电子邮件地址 [< a href =http://www.regular-expressions.info/email.htmltarget =_ blanktitle =新窗口> ^ ]



对于电子邮件,您也可以使用:如何:验证字符串是有效的电子邮件格式 [ ^ ]



说到电话号码,这取决于你来自哪个国家,以及你想要包括国际前缀等



这是瑞典的一个例子:

You can use regular expressions to do the validation.
Here is a good place to start: Regular-Expressions.info: Regular Expressions Tutorial[^]
and here too: Regular Expression Language - Quick Reference[^]

More specifically for validating emails you can start here: How to Find or Validate an Email Address[^]

For emails you can also use this: How to: Verify that Strings Are in Valid Email Format[^]

When it comes to phone numbers it depends a little on what country you are from and if you want to include international prefixes etc.

This is an example from Sweden:
08-1234567
054-123456
0550-12345



正则表达式


Regex

[0-9]{2,4}-[0-9]{5,7}



C#


C#

Regex regex = new Regex(@"[0-9]{2,4}-[0-9]{5,7}");
if (!regex.IsMatch(inputString))
    throw new Exception("Not a valid Swedish phone number.");





在上面的示例中,我没有注意两位数的区号不能少的情况超过本地部分的6位数。



In the example above I don't take care of the case that an area code with two digits, cannot have less than 6 digits in the local part.


这篇关于电子邮件和电话号码的CSV列验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆