working on it ...

Filters

Explore Public Snippets

Sort by

Found 2,379 snippets matching: verify

    public by cghersi  3292  2  8  0

    C#: How to dinamically check a string and its length using a Regex

    Thsi method creates a Regex by replacing a placeholder as minimum and maximum length (e.g. in case of username and / or password verifiers...). It can be extended also to apply different Regex with respect to some particular business logic.
    static private string s_nameRegEx = @"^[_a-zA-Z][_a-zA-Z0-9-. ]{ç,§}$"; //'ç' is a placeholder for actual minimum length, '§' is a placeholder for actual maximum length
            
    public static bool NameIsValid(string candidateName, int minimumLen, bool checkOnlyLen, int maxLen = int.MaxValue)
    {
        if (candidateName == null)
            return (minimumLen == 0); //return false if there's a minimum len
        string trimmedName = candidateName.Trim();
        if ((trimmedName.Length < minimumLen) || (trimmedName.Length > maxLen))
            return false;
        if (checkOnlyLen)
            return true;
        Regex nameExpr = new Regex(s_nameRegEx.Replace("ç", (minimumLen - 1) + "").Replace("§", (maxLen - 1) + ""));
        return nameExpr.IsMatch(trimmedName);
    }
    

    public by Geometry  1237  0  5  0

    DecodeChecked: Uses the checksum in the last 4 bytes of the decoded data to verify the rest are correct. The checksum is removed from the returned data.

    Uses the checksum in the last 4 bytes of the decoded data to verify the rest are correct. The checksum is removed from the returned data. If the input is not base 58 or the checksum does not validate.
    using System;
    using System.Linq;
    using System.Text;
    using CoiniumServ.Coin.Address.Exceptions;
    using CoiniumServ.Cryptology;
    using Org.BouncyCastle.Math;
    
    /// <summary>
    /// Uses the checksum in the last 4 bytes of the decoded data to verify the rest are correct. The checksum is
    /// removed from the returned data.
    /// </summary>
    /// <exception cref="AddressFormatException">If the input is not base 58 or the checksum does not validate.</exception>
    public static byte[] DecodeChecked(string input)
    {
        var tmp = Decode(input);
        if (tmp.Length < 4)
            throw new AddressFormatException("Input too short");
        var checksum = new byte[4];
        Array.Copy(tmp, tmp.Length - 4, checksum, 0, 4);
        var bytes = new byte[tmp.Length - 4];
        Array.Copy(tmp, 0, bytes, 0, tmp.Length - 4);
        tmp = bytes.DoubleDigest();
        var hash = new byte[4];
        Array.Copy(tmp, 0, hash, 0, 4);
        if (!hash.SequenceEqual(checksum))
            throw new AddressFormatException("Checksum does not validate");
        return bytes;
    }

    public by Tech_JA  2419  1  6  2

    Verify if at least one checkbox is checked

    This snippet verifies if at least one item of list[] is checked
    <?php
      var TestCheckbox = document.getElementsByName("list[]");
      var IsChecked = 0 ;
      for (var x = 0 , y = TestCheckbox.length ; x<y ; x++ ){
      	if (TestCheckbox[x].checked){
    		  IsChecked = 1;
    	  }
      }
      if (IsChecked){
      	alert("checked...");
      }else{
      	alert("not checked...");
    }
    ?>            

    public by lbottaro  2737  0  6  1

    C# linq expression to check all data in a given List

    This c# linq lambda function example shows how to verify if all items in a List are present in another List object. You don't need to loop or iterate for each element, just use the All extension method.
    List<string> myList = new List<string>();
    myList.Add("123");
    myList.Add("456");
    
    // myTargetList is a given List<string>
    
    Assert.IsTrue(myList.All(x => myTargetList.Contains(x)), "myList has element missing in myTargetList!"));

    public by zonaro  1566  1  7  0

    IsBlank

    Verify if string based object IsBlank, like string.IsNullOrWhiteSpace() method, but allows you to use like a extension method in any string convertilble object
    public static bool isBlank(this object Text)
            {
                return string.IsNullOrWhiteSpace("" + Text);
            }

    public by msdn  192690  0  7  0

    VerifyName: Verify that the supplied name is valid for Service Name, Database Name, Cluster Name and Storage Name. The size limits are Storage accounts must be at least 3 characters and Cluster Names cannot be more than 15 characte...

    Verify that the supplied name is valid for Service Name, Database Name, Cluster Name and Storage Name. The size limits are Storage accounts must be at least 3 characters and Cluster Names cannot be more than 15 characters. Storage Names are the most restricted in that they can only contain lower case letters and numbers. true if valid
    using System;
    using System.Text.RegularExpressions;
    
    /// <summary>
    /// Verify that the supplied name is valid for Service Name, Database Name, Cluster Name and Storage Name.
    /// The size limits are Storage accounts must be at least 3 characters and Cluster Names cannot be more
    /// than 15 characters.
    /// Storage Names are the most restricted in that they can only contain lower case letters and numbers.
    /// </summary>
    /// <returns>true if valid</returns>
    static public bool VerifyName(string name)
    {
        if (String.IsNullOrEmpty(name))
            return false;
        return Regex.IsMatch(name, "^[a-z0-9]{3,15}$", RegexOptions.Singleline);
    }

    public by msdn  102203  0  6  0

    IsGuid: Verify if the string is a valid Guid

    Verify if the string is a valid Guid
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using Microsoft.SharePoint;
    
    /// <summary>
    /// Verify if the string is a valid Guid
    /// </summary>
    /// <param name="candidate"></param>
    /// <param name="output"></param>
    /// <returns></returns>
    private static bool IsGuid(string candidate, out Guid output)
    {
        Regex isGuid = new Regex(@"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$", RegexOptions.Compiled);
    
        bool isValid = false;
        output = Guid.Empty;
        if (candidate != null)
        {
    
            if (isGuid.IsMatch(candidate))
            {
                output = new Guid(candidate);
                isValid = true;
            }
        }
        return isValid;
    }

    public by msdn  1017  0  7  0

    VerifySucceeded: Verify if an operation succeeded

    Verify if an operation succeeded
    /// <summary>
    /// Verify if an operation succeeded
    /// </summary>
    /// <param name="hresult"></param>
    public static void VerifySucceeded(UInt32 hresult)
    {
        if (hresult > 1)
        {
            throw new Exception("Failed with HRESULT: " + hresult.ToString("X"));
        }
    }

    public by msdn  1297  0  7  0

    GetAndVerifyLicense: Retrieves a license from SP and calls the store verification service to process it. Note that a verified license is NOT necessarily a valid license. You MUST still check the license properties to verify its validity

    Retrieves a license from SP and calls the store verification service to process it. Note that a verified license is NOT necessarily a valid license. You MUST still check the license properties to verify its validity The ProductId of your app, get this from your AppManifest.xml An already wired up SP ClientContext object
    using LicenseSPAppSampleWeb.LicenseVerificationService;
    using Microsoft.SharePoint.Client;
    using System;
    using System.Web;
    using System.Xml;
    
    /// <summary>
    /// Retrieves a license from SP and calls the store verification service to process it. 
    /// Note that a verified license is NOT necessarily a valid license. You MUST still check the license properties to verify its validity
    /// </summary>
    /// <param name="productId">The ProductId of your app, get this from your AppManifest.xml</param>
    /// <param name="ctx"> An already wired up SP ClientContext object</param>
    public static VerifyEntitlementTokenResponse GetAndVerifyLicense(Guid productId, ClientContext ctx)
    {
        //Retrieve license from SharePoint
        string rawLicense = GetLicenseTokenFromSharePoint(productId, ctx);
    
        if (String.IsNullOrEmpty(rawLicense))
        {
            return null;// No license
        }
    
        //Validate license with the store
        VerifyEntitlementTokenResponse storeLicense = GetValidatedLicenseFromStore(rawLicense);
        return storeLicense;
    
    }

    public by msdn  1035  0  6  0

    HasAncestor: Verify if the type of the ancestor is contained in the ignored types

    Verify if the type of the ancestor is contained in the ignored types
    using System.Linq;
    using System.Windows;
    using System.Windows.Interactivity;
    using System;
    using System.Windows.Input.Manipulations;
    using MultiTouch.ManipulationLib.Silverlight4;
    using System.Windows.Controls;
    using System.Windows.Threading;
    using System.Windows.Input;
    using System.Collections.Generic;
    using System.Windows.Media;
    using System.Windows.Shapes;
    using System.Windows.Controls.Primitives;
    
    #endregion
    
    #region Touch handlers
    
    /// <summary>
    /// Verify if the type of the ancestor is contained in the ignored types
    /// </summary>
    private static bool HasAncestor(DependencyObject child, IEnumerable<Type> types)
    {
        var parent = VisualTreeHelper.GetParent(child) as UIElement;
        if (parent == null) { return false; }
        if (types.Any(t => parent.GetType() == t))
        {
            return true;
        }
        return parent != Application.Current.RootVisual && HasAncestor(parent, types);
    }
    • Public Snippets
    • Channels Snippets