首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >验证AlphaNumeric XSLT

验证AlphaNumeric XSLT
EN

Stack Overflow用户
提问于 2022-08-27 00:32:50
回答 1查看 35关注 0票数 0

我被证实了。我可以在空字符串时验证,用长度要求验证,用数字验证,但是当输入有一个特殊字符并且包含字母数字时。我被困住了。有人能帮我纠正我需要用代码修复的那一面吗?

MYCODE:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="LOCAL_XSLT_Validate" xmlns="http://ws.apache.org/ns/synapse">
    <xsl:stylesheet version="1.0" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
        <xsl:template match="/">
            <OperationValueRegex>
                <xsl:call-template name="values">
                    <xsl:with-param name="vals" select="//OperationValueRegex/Value"/>
                </xsl:call-template>
            </OperationValueRegex>
        </xsl:template>
        <xsl:template name="values">
            <xsl:param name="vals"/>
            <xsl:choose>
                <!-- Validation Number -->
                <xsl:when test="fn:tokenize($vals, ' ')[matches(., '\d+')] and string-length($vals) = 8">
                    <Result1>
                        <xsl:value-of select="$vals"/>
                    </Result1>
                </xsl:when>
                <xsl:when test="$vals = 'NaN' or string-length($vals) != 8">
                    <Result1>
                        <Value>
                            <xsl:value-of select="$vals"/>
                        </Value>
                        <notification>input was not valid requirement maximum</notification>
                    </Result1>
                </xsl:when>
                <xsl:otherwise>
                    <Result1>
                        <Value>
                            <xsl:value-of select="$vals"/>
                        </Value>
                        <notification>Wrong Format</notification>
                    </Result1>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
    </xsl:stylesheet>
</localEntry>

请求和预期结果

代码语言:javascript
复制
{
    "OperationValueRegex" : {
        "Value" : "1234asdv"
    }
}


<OperationValueRegex xmlns="http://ws.apache.org/ns/synapse" xmlns:fn="http://www.w3.org/2005/xpath-functions">
    <Result1>1234asdv</Result1>
    <notification>Wrong Format</notification>
</OperationValueRegex>

谢谢

EN

回答 1

Stack Overflow用户

发布于 2022-08-27 12:13:26

我可以找到验证字母数字的方法

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="LOCAL_XSLT_Validate" xmlns="http://ws.apache.org/ns/synapse">
    <xsl:stylesheet version="1.0" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
        <xsl:template match="/">
            <OperationValueRegex>
                <xsl:call-template name="values">
                    <xsl:with-param name="vals" select="//OperationValueRegex/Value"/>
                </xsl:call-template>
                <xsl:call-template name="dates">
                    <xsl:with-param name="dats" select="//OperationValueRegex/Date"/>
                </xsl:call-template>
            </OperationValueRegex>
        </xsl:template>
        <xsl:template name="values">
            <xsl:param name="vals"/>
            <xsl:choose>
                <!-- Validation Number -->
                <xsl:when test="fn:matches($vals, '^\d+$') and string-length($vals) = 8">
                    <Result1>
                        <xsl:value-of select="$vals"/>
                    </Result1>
                </xsl:when>
                <xsl:when test="$vals = 'NaN' or string-length($vals) != 8">
                    <Result1>
                        <Value>
                            <xsl:value-of select="$vals"/>
                        </Value>
                        <notification>input was not valid requirement maximum</notification>
                    </Result1>
                </xsl:when>
                <xsl:when test="fn:matches($vals, '^[a-zA-Z0-9_]*$') and string-length($vals) > 0">
                    <Value>
                        <xsl:value-of select="$vals"/>
                    </Value>
                    <notification>Wrong Format</notification>
                </xsl:when>
            </xsl:choose>
        </xsl:template>
        <xsl:template name="dates">
            <xsl:param name="dats"/>
            <xsl:variable name="dateString">
                <xsl:value-of select="substring($dats,1,4)"/>
                <xsl:text>-</xsl:text>
                <xsl:value-of select="substring($dats,5,2)"/>
                <xsl:text>-</xsl:text>
                <xsl:value-of select="substring($dats,7,2)"/>
            </xsl:variable>
            <RequiredFormat>
                <xsl:value-of select="format-date(xs:date($dateString), '[Y]/[M]/[D]')"/>
            </RequiredFormat>
            <OtherFormat>
                <xsl:value-of select="format-date(xs:date($dateString), '[MNn] [D], [Y]')"/>
            </OtherFormat>
        </xsl:template>
    </xsl:stylesheet>
</localEntry>

但是,当输入具有=“@+./!‘*%^$()-@”这样的特殊字符时,我仍然有问题。在这方面不需要更多的帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73507603

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档