如何验证xml模式中的电子邮件ID [英] How to validate an email id in xml schema

查看:165
本文介绍了如何验证xml模式中的电子邮件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个模式来检查电子邮件ID。如果电子邮件id是abc@def.com和adbc@def.co.in和abc@def.co.in.pune
可以验证,但我只想验证abc@def.com和adbc @ def .co.in因为我认为电子邮件可以在@符号
后最多2个点,所以第三个将无效电子邮件id
那么如何使用模式验证电子邮件ID
下面是模式

 < xsd:element name =SSEMminOccurs =0> 
< xsd:complexType>
< xsd:sequence>
< xsd:element name =CNTminOccurs =0maxOccurs =unbounded>
< xsd:complexType>
< xsd:sequence>
< xsd:element name =EMminOccurs =1nillable =truetype =singleEmailID/>
< / xsd:sequence>
< / xsd:complexType>
< / xsd:element>
< / xsd:sequence>
< / xsd:complexType>
< / xsd:element>








感谢
Sunil Kumar Sahoo

解决方案

以定义与有效电子邮件相匹配的模式。使用正则表达式语法定义模式。一旦您使用适当的模式定义了一个简单类型(基于 xs:string ),您可以使用该类型作为您的电子邮件类型。



互联网上有几个地方提供了这些类型和模式的一些例子。 此处提供了电子邮件类型的示例。



给出的示例如下(我稍加修改,使事情更清晰一些):

 < xsd:schema xmlns:xsd =http://www.w3.org/2001/XMLSchema> 

< xsd:element name =Atype =emailAddress/>

< xsd:simpleType name =emailAddress>
< xsd:restriction base =xsd:string>
< xsd:pattern value =[^ @] + @ [^ \。] + \ .. +/>
< / xsd:restriction>
< / xsd:simpleType>
< / xsd:schema>


Hi I have created a schema to check for email id. which can validate if the email id is abc@def.com and adbc@def.co.in and abc@def.co.in.pune But i want to validate only abc@def.com and adbc@def.co.in because i think email can have maximum 2 dots after @ symbol so the third one will be invalid email id So how to validate an email id using schema Below is the schema

<xsd:element name="SSEM" minOccurs="0">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="CNT" minOccurs="0" maxOccurs="unbounded">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="EM" minOccurs="1" nillable="true" type ="singleEmailID"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

Thanks Sunil Kumar Sahoo

解决方案

You will need to define a pattern to match against valid e-mails. Patterns are defined using regular expression syntax. Once you have defined a simple type (based on xs:string) with the appropriate pattern, you can use that for your e-mail type.

There are several places on the Internet that provide some examples of such types and patterns. An example of an e-mail type is provided here.

The example given there is as follows (I've edited it slightly to make things a little clearer):

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" > 

  <xsd:element name="A" type="emailAddress"/> 

  <xsd:simpleType name="emailAddress"> 
    <xsd:restriction base="xsd:string"> 
      <xsd:pattern value="[^@]+@[^\.]+\..+"/> 
    </xsd:restriction> 
  </xsd:simpleType> 
</xsd:schema>

这篇关于如何验证xml模式中的电子邮件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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