自定义正则表达式列

    技术2022-05-20  35

    仅仅需要两个文件

    SingleLineVerificationFile.cs

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using System.Text.RegularExpressions; namespace SingleLineWithVerification { class SingleLineVerificationFile : SPFieldText { public SingleLineVerificationFile(SPFieldCollection fields, string fieldName) : base(fields, fieldName) { } public SingleLineVerificationFile(SPFieldCollection fields, string fieldName, string displayName) : base(fields, fieldName, displayName) { } //public override BaseFieldControl FieldRenderingControl //{ // get // { // BaseFieldControl fieldControl = new SingleLineVerificationControl(); // fieldControl.FieldName = this.InternalName; // return fieldControl; // } //} public override string GetValidatedString(object value) { string textValue = value.ToString(); if (textValue.Length > 0) { Regex reg = new Regex(GetCustomProperty("RegularExpression").ToString(), RegexOptions.IgnoreCase); if (!reg.IsMatch(textValue)) { throw new SPFieldValidationException(GetCustomProperty("ExceptionMessage").ToString()); } else { return textValue; } } else { return textValue; } } } }

    fldtypes_SingleLineVerification.xml

    <?xml version="1.0" encoding="utf-8" ?> <FieldTypes> <FieldType> <Field Name="TypeName">SingleLineVerification</Field> <Field Name="ParentType">Text</Field> <Field Name="TypeDisplayName">SingleLineVerification</Field> <Field Name="TypeShortDescription">SingleLineVerification</Field> <Field Name="UserCreatable">TRUE</Field> <Field Name="ShowOnListCreate">TRUE</Field> <Field Name="ShowOnSurveyCreate">TRUE</Field> <Field Name="ShowOnDocumentLibrary">TRUE</Field> <Field Name="ShowOnColumnTemplateCreate">TRUE</Field> <Field Name="Sortable">TRUE</Field> <Field Name="Filterable">TRUE</Field> <Field Name="FieldTypeClass">SingleLineWithVerification.SingleLineVerificationFile, SingleLineWithVerification, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc0df744664bc045</Field> <PropertySchema> <Fields> <Field Name="RegularExpression" DisplayName="Regular Expression" MaxLength="255" DisplaySize="35" Type="Text"> <Default></Default> </Field> <Field Name="ExceptionMessage" DisplayName="Exception Message" MaxLength="255" DisplaySize="35" Type="Text"> <Default></Default> </Field> </Fields> </PropertySchema> <Field Name="SQLType">nvarchar</Field> </FieldType> </FieldTypes>

    结果:

    其他操作请参考:http://blog.csdn.net/jack43349489/archive/2011/02/17/6191911.aspx


    最新回复(0)