If I want to make an if statement where it checks if the textfield is empty, how do I do it?
I tried this;
if(jTextField4.getText().equals(""))
Use StringUtils to check :
if(StringUtils.isEmpty(jTextField4.getText())
This will check if the String is null or empty with trimming the string.
If you do not like 3rd party library:
try this
String s = jTextField4.getText();
if(s != null && s.trim().equals(""))
So also all inputs that only contains blank are "empty".
Related
I have a function that stripes HTML markup to display inside of a text element.
stripChar: function stripChar(string) {
string = string.replace(/<\/?[^>]+(>|$)/g, "")
string = string.trim()
string = string.replace(/(\n{2,})/gm,"\n\n");
string = string.replace(/…/g,"...")
string = string.replace(/ /g,"")
let changeencode = entities.decode(string);
return changeencode;
}
This has worked great for me, but I have a new requirement and Im struggle to work out where I should start refactoring the code above. I still need to stripe out the above, but I have 2 exceptions;
List items, <ul><li>, I need to handle these so that they still appear as a bullet point
Hyperlinks, I want to use the react-native-hyperlink, so I need to leave intack the <a> for me to handle separately
Whilst the function is great for generalise tag replacement, its less flexible for my needs above.
You may use
stripChar: function stripChar(string) {
string = string.replace(/ |<(?!\/?(?:li|ul|a)\b)\/?[^>]+(?:>|$)/g, "");
string = string.trim();
string = string.replace(/\n{2,}/g,"\n\n");
string = string.replace(/…/g,"...")
let changeencode = entities.decode(string);
return changeencode;
}
The main changes:
.replace(/ /g,"") is moved to the first replace
The first replace is now used with a new regex pattern where the li, ul and a tags are excluded from the matches using a negative lookahead (?!\/?(?:li|ul|a)\b).
See the updated regex demo here.
I want to use arrayformula for my custom function if possible because I want to input a range of values
I also get this error: TypeError: Cannot read property "0" from null.
Also, this: Service invoked too many times in a short time: exec qps. Try Utilities.sleep(1000) between calls
var regExp = new RegExp("Item: ([^:]+)(?=\n)");
var matches=new regExp(input);
return matches[0];
}
Really appreciated some help
Edit:
Based on the second picture, I also try using this regex formula to find word start with "Billing address"
But for the first picture, I used regex formula to find word start with "Item"
The error appears the same for both custom function.
If you want to use a custom function which finds all the strings that start with Item or item and extracts the contents from after the finding, you can use the code provided below. The regular expression is checked by using the match() function and returns the desired result; otherwise, it will return null.
function ITEM(input) {
var regEx = /(?:I|i)tem\s*(.*)$/;
var matches = input.match(regEx);
if (matches && matches.length > 1) {
return matches[1];
} else {
return null;
}
}
If you want to use the RegExp like you did in the code you have shared, you should use \\ instead of \.
For checking and verifying the regular expressions you can use this site.
The Service invoked too many times in a short time: exec qps. Try Utilities.sleep(1000) between calls. error message you are getting is due to the fact that you are trying to call the custom function on too many cells - for example dragging the custom function on too many cells at once. You can check more about this error message here.
on oneButtonClicked_(sender)
set faceNumber's setStringValue() to faceNumber's stringValue() & "1"
end oneButtonClicked_
I get this error: "Can’t make «class ocid» id «data optr000000000058B37BFF7F0000» into type list, record or text. (error -1700)"
faceNumber is a label and when the user clicks the button, I want to add string of "1" to it. So for example, if the user clicked the button 5 times
stringValue returns an NSString(wrong answer) CFString. You have to make a real AppleScript String to use it.
BTW your code set faceNumber's setStringValue() is not correct. The reasons are:
The Cocoa handlers are always using the underscore.
If you use the setter setStringValue() you don't need to use set x to
If you want to use setStringValue() you must give the parameter between the parentheses
Now put everything together:
on oneButtonClicked_(sender)
faceNumber's setStringValue_((faceNumber's stringValue) as string & "1")
end oneButtonClicked_
or (to have it clearer):
on oneButtonClicked_(sender)
tell faceNumber
set currentValue to (its stringValue) as string
setStringValue_(currentValue & "1")
end tell
end oneButtonClicked_
I hope you like the answer, after pressing the button twice you have an 11 at the end of the label.
Cheers, Michael / Hamburg
Everything I've found indicates that an empty string can be matched in a regular expression by /^$/. However, that expression is not working in my Mongoose Validator for zipcode.
I want to set zipcode if one of two states is true - either it is empty or it is a valid, five digit number.
ZIP_REGEX: /^$|^[0-9]{5}$/
zip: {
type: Number,
validate: [ ZIP_REGEX, 'ValidationError']
},
This validator fails each time I attempt to store an empty string. The result is I can set valid zipcode, but never unset them. Is Mongoose also trying to verify that the empty string is a Number? Is the regular expression wrong?
Use a custom validation function for anything a bit unusual like this. Assuming you want to support both numbers and strings as input:
function validator(v) {
return (!v && v !== 0) || /^[0-9]{5}$/.test(v.toString());
};
zip: {
type: Number,
validate: [validator, 'ValidationError']
},
I have a grid with certain records and a textfield above it. The textfield is connected with the grid such that each time there is a keyup event it goes to a filter function in order to only show those records that contain the characters that the user typed in. The problem is that right now it only matches from the starting character of the record string name, however id like it to be able to filter all those records that contain the typed in characters anywhere in the record string name.
Screenshots:-
http://imgur.com/a/qvIHO
The first image shows the records, second shows the filtered results when i type in 'c', the third shows that when i press in 'p' it doesn't return any result however i want it to return "GPL Products" and "Reporting Period" since they both contain 'p' in them.
Here's the code:-
onDimensionFilterTextBoxKeyUp: function (filterTxtBox, evntObj, eOpts) {
var dimStore = this.getDimensionStoreStore();
//get new value
var searchValue = filterTxtBox.getValue();
//var regex = /searchValue*/;
//clear previous search value
dimStore.clearFilter();
if (!Ext.isEmpty(searchValue)) {
//load filtered data
dimStore.filter('DimensionName', searchValue);
}
}
I tried creating a regexp pattern using the /searchValue*/ but using that just breaks the filter and it doesn't return even a single result.
Try this:
re = new RegExp(searchValue, ignoreCase ? 'i' : '');
store.filter(field, re);
You just need to specify a case-insensitive search.
dimStore.filter('DimensionName', searchValue, true, false);
I know that those answers above are old, but maybe can help someone.
store.filter({
anyMatch: true,
exactMatch: false,
property: valor_property,
value: valor
});