Imports System.Text.Encoding
Imports System.Text.RegularExpressions
Public Class Validate
Public Function IsHankaku(ByVal str As String) As Boolean
Dim Bytelen As Integer = System.Text.Encoding.GetEncoding("shift_jis").GetByteCount(str)
Return str.Length = Bytelen
End Function
Public Overridable Function IsPostalCode(ByVal str As String) As Boolean
Dim RegExp As New Regex("^[0-9]{3}-[0-9]{4}$")
If RegExp.IsMatch(str) Then
Return True
Else
Return False
End If
End Function
Public Overridable Function IsNumber(ByVal str As String) As Boolean
'http://www.atmarkit.co.jp/bbs/phpBB/viewtopic.php?forum=7&topic=26783
'Dim RegExp As New Regex("^[0-9]+$") '半角の数字のみ
Dim RegExp As New Regex("^[-.0-9]+$") '半角の数字のみ'1.0 -1,-のみ なども含む
If str.Substring(0, 1) = String.Empty Then
Return False
End If
'マイナスだけでもtrueになってしまうので
If str.Substring(0, 1) = "-" AndAlso str.Length = 1 Then
Return False
End If
If RegExp.IsMatch(str) Then
Return True
Else
Return False
End If
End Function
Public Function IsDateFormatBySlash(ByVal strDate As String) As Boolean
Dim regExp As New Regex("^[0-9]{4}/[0-9]{2}/[0-9]{2}") '数字4/数字2/数字2
If IsDate(strDate) Then
If regExp.IsMatch(strDate) Then
Return True
Else
Return False
End If
Else
Return False
End If
End Function
Public Function IsDateFormatByHaihun(ByVal strDate As String) As Boolean
Dim regExp As New Regex("^[0-9]{4}-[0-9]{2}-[0-9]{2}") '数字4/数字2/数字2
If IsDate(strDate) Then
If regExp.IsMatch(strDate) Then
Return True
Else
Return False
End If
Else
Return False
End If
End Function
End Class
Imports Microsoft.VisualBasic
Public Class Converter
Public Function ConvertZenkakuToHankaku(ByVal str As String) As String
Return Strings.StrConv(str, VbStrConv.Narrow) ' 数字、カタカナを半角に変換 C#にはないので、VisualBasicをインポートしてあげる
End Function
End Class
0 件のコメント:
コメントを投稿