Skip to content

Commit 8434651

Browse files
committed
修复model验证不能识别负数的问题
1 parent 56653d7 commit 8434651

File tree

4 files changed

+58
-54
lines changed

4 files changed

+58
-54
lines changed

Vue.Net/VOL.Core/Extensions/EntityProperties.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -827,16 +827,17 @@ public static (bool, string, object) ValidationVal(this string dbType, object va
827827
}
828828
else if (dbType == SqlDbTypeName.Float || dbType == SqlDbTypeName.Decimal || dbType == SqlDbTypeName.Double)
829829
{
830-
string formatString = string.Empty;
831-
if (propertyInfo != null)
832-
formatString = propertyInfo.GetTypeCustomValue<DisplayFormatAttribute>(x => x.DataFormatString);
830+
//string formatString = string.Empty;
831+
//if (propertyInfo != null)
832+
// formatString = propertyInfo.GetTypeCustomValue<DisplayFormatAttribute>(x => x.DataFormatString);
833833
//if (string.IsNullOrEmpty(formatString))
834834
// throw new Exception("请对字段" + propertyInfo?.Name + "添加DisplayFormat属性标识");
835835

836-
if (!val.IsNumber(formatString))
836+
if (!val.IsNumber(null))
837837
{
838-
string[] arr = (formatString ?? "10,0").Split(',');
839-
reslutMsg = $"整数{arr[0]}最多位,小数最多{arr[1]}位";
838+
// string[] arr = (formatString ?? "10,0").Split(',');
839+
// reslutMsg = $"整数{arr[0]}最多位,小数最多{arr[1]}位";
840+
reslutMsg = "不是有效数字";
840841
}
841842
}
842843
else if (dbType == SqlDbTypeName.UniqueIdentifier)

Vue.Net/VOL.Core/Extensions/StringExtension.cs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -185,26 +185,27 @@ public static bool IsDate(this object str, out DateTime dateTime)
185185
/// <returns></returns>
186186
public static bool IsNumber(this string str, string formatString)
187187
{
188-
if (string.IsNullOrEmpty(str))
189-
return false;
190-
int precision = 32;
191-
int scale = 5;
192-
try
193-
{
194-
if (string.IsNullOrEmpty(formatString))
195-
{
196-
precision = 10;
197-
scale = 2;
198-
}
199-
else
200-
{
201-
string[] numbers = formatString.Split(',');
202-
precision = Convert.ToInt32(numbers[0]);
203-
scale = numbers.Length == 0 ? 2 : Convert.ToInt32(numbers[1]);
204-
}
205-
}
206-
catch { };
207-
return IsNumber(str, precision, scale);
188+
if (string.IsNullOrEmpty(str)) return false;
189+
190+
return Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$");
191+
//int precision = 32;
192+
//int scale = 5;
193+
//try
194+
//{
195+
// if (string.IsNullOrEmpty(formatString))
196+
// {
197+
// precision = 10;
198+
// scale = 2;
199+
// }
200+
// else
201+
// {
202+
// string[] numbers = formatString.Split(',');
203+
// precision = Convert.ToInt32(numbers[0]);
204+
// scale = numbers.Length == 0 ? 2 : Convert.ToInt32(numbers[1]);
205+
// }
206+
//}
207+
//catch { };
208+
//return IsNumber(str, precision, scale);
208209
}
209210
/**/
210211
/// <summary>
@@ -226,7 +227,7 @@ public static bool IsNumber(this string str, int precision, int scale)
226227
pattern += @"\.\d{0," + scale + "}$)|" + pattern;
227228
}
228229
pattern += "$)";
229-
return Regex.IsMatch(str, pattern);
230+
return Regex.IsMatch(str, pattern);
230231
}
231232

232233

开发版dev/Vue.NetCore/Vue.Net/VOL.Core/Extensions/EntityProperties.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -827,16 +827,17 @@ public static (bool, string, object) ValidationVal(this string dbType, object va
827827
}
828828
else if (dbType == SqlDbTypeName.Float || dbType == SqlDbTypeName.Decimal || dbType == SqlDbTypeName.Double)
829829
{
830-
string formatString = string.Empty;
831-
if (propertyInfo != null)
832-
formatString = propertyInfo.GetTypeCustomValue<DisplayFormatAttribute>(x => x.DataFormatString);
830+
//string formatString = string.Empty;
831+
//if (propertyInfo != null)
832+
// formatString = propertyInfo.GetTypeCustomValue<DisplayFormatAttribute>(x => x.DataFormatString);
833833
//if (string.IsNullOrEmpty(formatString))
834834
// throw new Exception("请对字段" + propertyInfo?.Name + "添加DisplayFormat属性标识");
835835

836-
if (!val.IsNumber(formatString))
836+
if (!val.IsNumber(null))
837837
{
838-
string[] arr = (formatString ?? "10,0").Split(',');
839-
reslutMsg = $"整数{arr[0]}最多位,小数最多{arr[1]}位";
838+
// string[] arr = (formatString ?? "10,0").Split(',');
839+
// reslutMsg = $"整数{arr[0]}最多位,小数最多{arr[1]}位";
840+
reslutMsg = "不是有效数字";
840841
}
841842
}
842843
else if (dbType == SqlDbTypeName.UniqueIdentifier)

开发版dev/Vue.NetCore/Vue.Net/VOL.Core/Extensions/StringExtension.cs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -185,26 +185,27 @@ public static bool IsDate(this object str, out DateTime dateTime)
185185
/// <returns></returns>
186186
public static bool IsNumber(this string str, string formatString)
187187
{
188-
if (string.IsNullOrEmpty(str))
189-
return false;
190-
int precision = 32;
191-
int scale = 5;
192-
try
193-
{
194-
if (string.IsNullOrEmpty(formatString))
195-
{
196-
precision = 10;
197-
scale = 2;
198-
}
199-
else
200-
{
201-
string[] numbers = formatString.Split(',');
202-
precision = Convert.ToInt32(numbers[0]);
203-
scale = numbers.Length == 0 ? 2 : Convert.ToInt32(numbers[1]);
204-
}
205-
}
206-
catch { };
207-
return IsNumber(str, precision, scale);
188+
if (string.IsNullOrEmpty(str)) return false;
189+
190+
return Regex.IsMatch(str, @"^[+-]?\d*[.]?\d*$");
191+
//int precision = 32;
192+
//int scale = 5;
193+
//try
194+
//{
195+
// if (string.IsNullOrEmpty(formatString))
196+
// {
197+
// precision = 10;
198+
// scale = 2;
199+
// }
200+
// else
201+
// {
202+
// string[] numbers = formatString.Split(',');
203+
// precision = Convert.ToInt32(numbers[0]);
204+
// scale = numbers.Length == 0 ? 2 : Convert.ToInt32(numbers[1]);
205+
// }
206+
//}
207+
//catch { };
208+
//return IsNumber(str, precision, scale);
208209
}
209210
/**/
210211
/// <summary>
@@ -226,7 +227,7 @@ public static bool IsNumber(this string str, int precision, int scale)
226227
pattern += @"\.\d{0," + scale + "}$)|" + pattern;
227228
}
228229
pattern += "$)";
229-
return Regex.IsMatch(str, pattern);
230+
return Regex.IsMatch(str, pattern);
230231
}
231232

232233

0 commit comments

Comments
 (0)