locked
validation in sharepoint designer for mobile number RRS feed

  • Question

  • i created a list in which i took a column mobile number for this column i want to do validation like it shud be 0000-0000 in style or 10 digit...or something else for that should i use javascript (regular expression)

    how can we apply validation controls as we do in asp.net?

    please help


    sudhanshu sharma
    • Moved by Mike Walsh FIN Friday, August 19, 2011 6:34 AM spd questions except wf go to the design/cust forum (From:SharePoint - Collaboration (pre-SharePoint 2010))
    Friday, August 19, 2011 6:12 AM

Answers

  • Hi ,

     

    You can choose ‘File’ option in  SharePoint designer to open site .Then choose the NewItem.aspx page of the list .Add a RegularExpressionValidator control on the page and bind it to the phone number column .

    Then you should set the Validation Expression as (\d{10})|(\d{4}-\d{4}) .

     

    For more detailed information ,please refer to this site:

    Adding Validation to a Custom List Control in Sharepoint : http://www.codeproject.com/KB/sharepoint/Control_validation.aspx

     

    Thanks,


    Entan Ming
    Tuesday, August 23, 2011 7:00 AM
    Moderator

All replies

  • Hi,

    You can try below script but i have not tested yet. so you may need to change this according to your requirement

    function PreSaveAction()
    {
        var x= getTagFromIdentifierAndTitle("INPUT","string","MobileNumber");
        if(isNaN(x)|| x.indexOf(" ")!=-1){
                  alert("Enter numeric value");return false; }
            if (x.length > 10 || x.length > 8 ){
                    alert("enter 10 or 8 characters"); return false;
               }
            if (x.charAt(0)!="9" || x.charAt(0)!="2"){
                    alert("it should start with 9 or 2 ");
                    return false
               }
    }

    Here is useful link:

    http://sharepointapplied.com/2009/01/08/sharepoint-forms-date-validation-using-javascript/

     


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"
    Friday, August 19, 2011 7:31 AM
    Moderator
  • hi hemendra,

    function PreSaveAction()
    {
        var x= getTagFromIdentifierAndTitle("INPUT","TextField","Contact Number");
        if(isNaN(x)|| x.indexOf(" ")!=-1)
        {
                  alert("Enter numeric value");
                  return false;
                   }
                  
             if (x.length >10)
              {
                    alert("enter 10 digit number");
                     return false;
               }
            return true;
    }
    by this code m always getting enter numeric field msg if i fill numeric but less than 10 number still m getting enter numeric ...msg

    i also try if(x.length<10) if ((x.length)!=10) all combination but o/p is not correct

    Friday, August 19, 2011 9:14 AM
  • Hi,

    Sorry for above script. Actually it was my mistake. Now try to use below script:


    <script type="text/javascript">

    function CustomValidation() {

    //perform your validations client side
    function PreSaveAction()
    {
      //get the first field   
      var x = getTagFromIdentifierAndTitle("INPUT","TextField","Contact Number");

    //check if x is not null
    if(x) 
    {
    if (x.value.length > 0)
    {
      if(isNaN(x) || x.indexOf(" ")! = -1)
        {
                  alert("Enter numeric value");
                  return false;
         }
                 
             if (x.length >10)
              {
                    alert("enter 10 digit number");
                     return false;
               }
            return true;
    }
    }
      return true; // OK to proceed with the save item
    }


    function getTagFromIdentifierAndTitle(tagName, identifier, title) {
     var len = identifier.length;
     var tags = document.getElementsByTagName(tagName);
     for (var i=0; i < tags.length; i++) {
      var tempString = tags[i].id;
      if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
       return tags[i];
      }
     }
     return null;
    }

    }
    </script>

    Let us know your result


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"
    Friday, August 19, 2011 9:57 AM
    Moderator
  • :(:(((((((:(((

    nothing worked:( donno why even while writing this code ..some hided fields are showing in my list :(... o/p .is strange..............  :(((((

     

    i wrote this-

    <script language="javascript" type="text/javascript">
    function getTagFromIdentifierAndTitle(tagName, identifier, title)
    {
       var len = identifier.length;
       var tags = document.getElementsByTagName(tagName);
       for (var i=0; i < tags.length; i++)
       {
          var tempString = tags[i].id;
          if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len))
            {
             return tags[i];
             }
        }
       return null;
    }
    function PreSaveAction()
    {
        
      var x = getTagFromIdentifierAndTitle("INPUT","TextField","Contact Number");

      if(isNaN(x) || x.indexOf(" ")! = -1)
        {
                  alert("Enter numeric value");
                  return false;
         }
                 
             if (x.length >10)
              {
                    alert("enter 10 digit number");
                     return false;
               }
      return true; // OK to proceed with the save item
    }


    </script>

    <script language="javascript" type="text/javascript">
    _spBodyOnLoadFunctionNames.push("fieldValidation");
    function fieldValidation()
    {
    var control=getTagFromIdentifierAndTitle("INPUT","TextField","Contact Number");

    }
    </script>

    :(


    sudhanshu sharma
    Friday, August 19, 2011 12:52 PM
  • Hi,

    You can do the above very easily in form validator.

    Refer this:

    http://www.sharepointboost.com/formvalidation.html

    Also there is a KB article for this. Refer this:

    http://support.microsoft.com/kb/891816

    I hope this will help you out.


    Thanks, Rahul Rashu
    Sunday, August 21, 2011 5:44 AM
  • Monday, August 22, 2011 5:50 AM
  • Hi there, I would like to recommend jQuery.Validate another alternative is Bamboos validate column. I wrote an blog about validation in SharePoint for a while ago, take a look here.
    / C
    Blog: chrisstahl.wordpress.com Twitter: @Cstahl
    Monday, August 22, 2011 7:04 AM
  • hi rahul,

    this i want to do....but i dont know when i open designer how to apply validate control-

    in my list for contact number column if i want to insert regular expression validator then how to do.....


    sudhanshu sharma
    Monday, August 22, 2011 11:07 AM
  • Hi ,

     

    You can choose ‘File’ option in  SharePoint designer to open site .Then choose the NewItem.aspx page of the list .Add a RegularExpressionValidator control on the page and bind it to the phone number column .

    Then you should set the Validation Expression as (\d{10})|(\d{4}-\d{4}) .

     

    For more detailed information ,please refer to this site:

    Adding Validation to a Custom List Control in Sharepoint : http://www.codeproject.com/KB/sharepoint/Control_validation.aspx

     

    Thanks,


    Entan Ming
    Tuesday, August 23, 2011 7:00 AM
    Moderator
  • hi Entan,

    This site was awesome i have done with validation it was like simple asp.net drag and drop validation control only need to do some work like  custom list form in designer .but this is not working for editForm.aspx

    but this expression didnt work ValidationExpression="\d{2}|\d{1}"

    i also tried ValidationExpression="(\d{2})|(\d{1}) only \d{2} is working if i want to apply | (or) then how can i apply?

    thanks for your help:)


    sudhanshu sharma

    Wednesday, August 24, 2011 6:08 AM
  • Please help for editForm.aspx ..........everything is working now for NewForm.aspx but nothing is going to work for EditForm.aspx what to do?

    :(

    :(

    :(


    sudhanshu sharma
    Wednesday, August 24, 2011 1:37 PM
  • Hi ,

     

    What do you mean by ‘nothing is going to work’ ? What is the error message ?Is it prompt that ‘the expression is invalid’ or when you type in some character is keeps showing the error message ?

     

    I have a test about the \d{2}|\d{1} .It is OK .This expression means that you have to type in one or two digits in the column .

     

    For more detailed information about the regular expression ,please refer to this site :

    Regular Expressions patterns: http://www.javascriptkit.com/javatutors/redev2.shtml

    How To: Use Regular Expressions to Constrain Input in ASP.NET: http://msdn.microsoft.com/en-us/library/ff650303.aspx

     

    Thanks,


    Entan Ming
    Thursday, August 25, 2011 1:23 AM
    Moderator