1

Am creating a custom list-forms using SP designer 2013 and trying to validate these fileds but whn am using the reguler expresion validator then am start getting error like

Web Part Error: The type System.Web.UI.WebControls.RegularExpressionValidator, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a could not be found or it is not registered as safe. Correlation ID: c079b19d-b12c-80c8-20ae-ed7f8ba6c71a. Hide Error Details [UnsafeControlException: The type System.Web.UI.WebControls.RegularExpressionValidator, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a could not be found or it is not registered as safe.] at Microsoft.SharePoint.EditingPageParser.VerifyControlOnSafeList(String dscXml, RegisterDirectiveManager registerDirectiveManager, SPWeb web) at Microsoft.SharePoint.ServerWebApplication.Microsoft.Web.Design.Server.IServerWebApplication.CheckMarkupForSafeControls(String controlMarkup, RegisterDirectiveManager registerDirectiveManager)
at Microsoft.Web.Design.Server.ServerDocument.CheckMarkupForSafeControls(String outerHtml) at Microsoft.Web.Design.Server.ServerDocument.Microsoft.Web.Design.Server.IServerDocumentDesigner.ParseControl(String outerHtml) at Microsoft.SharePoint.WebPartPages.SPWebPartManager.CompressUsingMicrosoftWebDesigner(SourceContent sourceContent, String allRegisterDirectives) at Microsoft.SharePoint.WebPartPages.SPWebPartManager.CompressInOrder(Deserializer firstMethod, Deserializer secondMethod, SourceContent sourceContent, String allRegisterDirectives, Boolean isClosed)


this error comes by simply adding validator to page

1

for validating list-forms fields we need to take either field id or value according to that we can validate any field.we can apply bellow code to achieve that

function PreSaveAction()
{
 var innerHtml="";
 var emailId = $("input[title='Email Id']")[0].value;
 var ContactNo=$("input[title='Contact No']")[0].value;
 var lngth=parseInt(ContactNo.length);
 var numExpression = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/; 
 var emailFilter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; // /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;

 if(emailId==="")
    {
        innerHtml+="Email Id can not be empty";
        $("#emailErrorMessage").html(innerHtml);   
        return false ;       
    }

    else if (emailFilter.test(emailId) === false) {
        innerHtml+="In-valid Email Id";
        $("#emailErrorMessage").html(innerHtml);   
        return false ;
     }
     else { 
         $("#emailErrorMessage").html(""); 
        return true ;
     }

 if(isNaN(parseInt(ContactNo))) {
         if(ContactNo==="")
         {
             innerHtml+="Contact No Can not be Empty";
             $("#contactNoErrorMessage").html(innerHtml);   
             return false ;
         }
         else
         {
             innerHtml+="you can enter only digits";
             $("#contactNoErrorMessage").html(innerHtml);   
             return false ;
         }
    }
    else if(!isNaN(parseInt(ContactNo)) && (lngth<10 ||lngth>10) )
    {
        innerHtml+="You can enter only 10 digits";
        $("#contactNoErrorMessage").html(innerHtml);   
        return false ;
    }

    else
    {  
        $("#contactNoErrorMessage").html("");   
        return true ;
    } 
} 


but for this we have to add a script editor web part to that list form and in that script editor web part we have to put the validation code like above mensioned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.