You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.8 KiB
C#

1 month ago
// ***********************************************************************
// Assembly : Construction
// Author : zjx
// Created : 07-28-2020
//
// Last Modified By : zjx
// Last Modified On : 09-01-2020
// ***********************************************************************
// <copyright file="Validation.cs" company="jindongfang">
// Copyright (c) jindongfang. All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
namespace WellWorkDataUI
{
using System;
using System.Text.RegularExpressions;
/// <summary>
/// Class Validation.
/// </summary>
public static class Validation
{
private static readonly Regex RegexNumber = new Regex(@"^[+-]?\d*[.]?\d*$", RegexOptions.Compiled);
/// <summary>
/// Determines whether [is date time] [the specified input].
/// </summary>
/// <param name="input">The input.</param>
/// <returns><c>true</c> if [is date time] [the specified input]; otherwise, <c>false</c>.</returns>
public static bool IsDateTime(string input)
{
return DateTime.TryParse(input, out DateTime _);
}
/// <summary>
/// Determines whether the specified input is decimal.
/// </summary>
/// <param name="input">The input.</param>
/// <returns><c>true</c> if the specified input is decimal; otherwise, <c>false</c>.</returns>
public static bool IsDecimal(string input)
{
return IsNumber(input) && input.Contains(".");
}
/// <summary>
/// Determines whether [is less than] [the specified input].
/// </summary>
/// <param name="input">The input.</param>
/// <param name="length">The length.</param>
/// <returns><c>true</c> if [is less than] [the specified input]; otherwise, <c>false</c>.</returns>
public static bool IsLessThan(string input, int length)
{
return input.Length < length;
}
/// <summary>
/// Determines whether [is not empty] [the specified input].
/// </summary>
/// <param name="input">The input.</param>
/// <returns><c>true</c> if [is not empty] [the specified input]; otherwise, <c>false</c>.</returns>
public static bool IsNotEmpty(string input)
{
return !string.IsNullOrWhiteSpace(input);
}
/// <summary>
/// Determines whether the specified input is number.
/// </summary>
/// <param name="input">The input.</param>
/// <returns><c>true</c> if the specified input is number; otherwise, <c>false</c>.</returns>
public static bool IsNumber(string input)
{
return RegexNumber.IsMatch(input);
}
}
}