I have a field "company name" that must never contain any numeric characters at all and it should contain only string alphabetic characters, how to validate that with yup?
Thanks to #IAmGroot
const schema = yup.object().shape({
company_name: yup
.string()
.matches(/^[a-z]+$/, 'Only alphabetic characters allowed')
})
Related
I have:
const schema = yup.object().shape({
title: yup.string().trim().required(),
taste: yup.string().defined(), // <<< this needs to be different
);
However, the title makes sense because a title can be any string, but for taste, it needs to be either "Sweet", "Salty", or "Spicy".
How do you do this with yup?
I have a schema:
const SignupSchema = Yup.object().shape({
decimal: Yup.number().integer('invalid decimal'),
});
I need to check if the number is a decimal, but I found only Integer in docs.
You can add a custom validation test e.g. with regex.
const SignupSchema = Yup.object().shape({
decimal: Yup.number().test(
'is-decimal',
'invalid decimal',
value => (value + "").match(/^\d*\.{1}\d*$/),
),
});
const digitsOnly = (value: string) => /^\d*[\.{1}\d*]\d*$/.test(value) || value.length === 0
const schema = yup.object().shape({
inputEntry: yup
.string()
.test('inputEntry', 'The field should have digits only', digitsOnly)
});
Above code is used for allowing only decimal,whole and null values in the input field.
just keep yup.number for decimals
I'm using Red Gate SQL Data Generator 3. What I'm wanting to do is to generate test data where there are related fields in each row. For example, I want to generate a row of data that looks like this:
Username: CONTOSO\FFlintstone
FullName: Flintstone, Fred
Email: FFlintstone#contoso.com
Programatically, I'd want something like (pseudo-code):
Generate _lastname, _firstname
_username = first-letter of _firstname + _lastname
Fullname = _lastname + ", " + _firstname
Username = "CONTOSO\" + _username
Email = _username + "#contoso.com"
All the data generator samples I saw were for a single field, and didn't allow or consider needing to populate a row with related fields. I did not see a means of doing this within the product directly. Also, at the moment, the user forums at Red-Gate are down, so no help there.
Is this possible to do within the product? If so, could somebody post an example?
As a proof of concept, I created a dummy table with a primary key and some fields - firstname, surname, username and email.
firstname was just set to the generic "First Name" generator, as the surname was set to the "Last Name" generator.
I then used the "Simple Expression" generator for the username and email fields. The expression for the username generator was 'CONTOSO\\'+firstname[:1]+surname. For the email column, the expression I used was firstname[:1].lower()+surname.lower()+'#contoso.com'
This image shows the resulting data I managed to generate
I hope this helps.
In this code:
The follow Const is set as Integers.
Private Const VendorID As Integer = &H1234 'Replace with your device's
Private Const ProductID As Integer = &H1234 'product and vendor IDs
Some product and vendor IDs have characters in them. Is this code for specific devices?
Thanks
Ralph
This is how you write hexadecimal values in VB.NET;
&H1234 is a hexadecimal value corresponding to 0x1234 in C#.
Background
A ResultSet has many Double value fields (with patterns like "###0.000"). Some values can be null.
Problem
I want to replace null values with "N/A", which is a String and cannot print to a Double field. Printing "0.00" for null values is unacceptable.
Using an PrintWhenExpression value of ($F{value} != null) ? $F{value} : "N/A" does not work; it is not possible to use patterns in that way.
Idea
Add hidden fields that write "N/A". These fields will be printed only if value is null.
Question
Is there a better solution, and if so, what is it?
Thank you.
Solution #1
Your solution:
Use a regular Double field (doubleField) for the column value.
Add a static String text field at the same location.
Change the Double field to Blank When Null.
Set the PrintWhenExpression value for the String text field to: $F{doubleField} == null.
Solution #2
The problem is, as you pointed out, that a Double and a String are two different data types. You can assign a String variable to the value of the Double using an appropriate expression. Then use the String variable as the field. The expression might resemble:
($F{doubleField} == null) ?
"N/A" : new java.text.DecimalFormat("#.##").format($F{doubleField})
(Note: My preference is to use == instead of !=. Think positive.)
Solution #3
Change the SQL statement to pre-format the Double as a text string, and use the "N/A" in the string (by using a CASE or DECODE statement in the query).
Avoid this solution, though, as it is not maintainable.
Recommendation
Do not hard-code the "N/A" string throughout the report(s); put the "N/A" text in a constant, or a parameter with a default value of "N/A".
You can try something like this in your field expression:
("Your static text "+(($F{field}!=null)?$F{field}:""))
Or, if you don't want your static text to be visible when the field is null, try putting $F{field}!=null in your PrintWhenExpression.