How do I restrict a field in a UD table to only numbers and not alphanumeric?
@Will79 - Could you enter >>>>>9 in the Format field in Extended Properties Maintenance for the UD table fields? Or add integer/decimal type UD fields for the UD table?
Create the field using either the Integer, Decimal, or Long type depending on which best suits what you want.
Andris’s comment about Extended Properties Maintenance will work if you don’t want to create a new field. Funny that we responded at the exact same time
That’s a string with 60 chars maximum, not a number. I would add a new correct field or maybe try and use the Numeric Editor instead of the TextBox in the customization.
You can try small C# code also.
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text, "[^0-9]"))
{
MessageBox.Show("Please enter only numbers.");
textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1);
}
}
The “Key” fields in UD tables are String data types by default and cannot be changed. As @fakhruddin indicates, you can use programming to restrict your users. A BPM could also do that, but it would only disallow saving of the record (they could enter in some text, but then when they saved it they’d get an error).
I’ve just realized I have something similar in UD100. I used a UD100.Update.Pre directive where if you have any added row in ttUD100 it will fire the code below which will populate a global BPM var coinvalid. You can then use that to show an error message if it’s true. It’s messy but it will do the job:
// reset vars
coinvalid = true;
// get added UD100 row
var ar = (from arrow in ttUD100 where (arrow.RowMod=="A") select arrow).FirstOrDefault();
if (ar!=null)
{
string k = ar.Key1;
int nk = 0;
bool rz = Int32.TryParse(k, out nk);
if (rz)
{
if (nk.ToString()==k && nk>0) coinvalid=false;
}
}
AS Ene indicated, I would use the NumericEditor, if key1-Key5 cannot be attached to it, attach it to a Number01 field, and with a BPM, save the string version to key1 before the save…
Pierre
So, I have it set to Numbero1, and it already populates Key1. Can’t find out why. I do not see any BPM’s that would do this that are active. Thoughts on this?