NGUI avoid line-break in UIInput - unity3d

Is there any way to avoid users to input line-breaks in UIInputs?
Do not want the user to be able to write line-breaks in username inputs, for example.
I searched for multiline attribute but it seems it only exists in UILabel objects.
Tried "validation:Username" but this option does not allow to write characters like "-", which is a valid username character of my application.
Thanks!

You can similarly limit your input field to a single line by setting the Max Lines property to 1 on the UILabel.
http://www.tasharen.com/forum/index.php?topic=6752.0

Had to check the UIInput.cs file to know how to ignore newlines, and I found this:
case KeyCode.KeypadEnter:
{
ev.Use();
bool newLine = (onReturnKey == OnReturnKey.NewLine) ||
(onReturnKey == OnReturnKey.Default &&
label.multiLine && !ctrl &&
label.overflowMethod != UILabel.Overflow.ClampContent &&
validation == Validation.None);
if (newLine)
{
//Insert("\n");
}
else
{
UICamera.currentScheme = UICamera.ControlScheme.Controller;
UICamera.currentKey = ev.keyCode;
Submit();
UICamera.currentKey = KeyCode.None;
}
return true;
}
So in order to avoid newlines, you need to do:
UILabelObject.multiLine = false;
UIInputObject.onReturnKey = UIInput.OnReturnKey.Default;
Doing that, bool newLine becomes false and performs Submit();

Related

Flutter/Dart - Username Validation - Checking for bad words

In the code below, we have a method which is called whenever the user clicks on the 'Sign Up' button (on our Authentication screen). Currently this method has two different conditions, if it doesn't pass these conditions, the user won't be able to sign up.
We'd also like to add one more condition here. We have an array of strings that shouldn't be accepted as usernames (bad words). But if the bad word is used in combination with other letters or numbers, it should also not be accepted.
Example of a "bad word": Charlie
That means Charlie shouldn't be accepted as a username but there's also potential for millions of other combinations, examples: Charlieee, Charlie124342, Charlie6648, 213charlie, ch1chaRliE32, etc. etc.
So would there be any simple method to check whether the username entered contains any of the bad words listed in an array, regardless of whether its used in combination with other characters or not?
Future<String?> usernameValidator({required String? username}) async {
// Validates username complexity
bool isUsernameComplex(String? text) {
final String _text = (text ?? "");
String? p = r"^(?=(.*[ #$!%*?&=_+/#^.~`]))";
RegExp regExp = RegExp(p);
return regExp.hasMatch(_text);
}
final String _text = (username ?? "");
// Complexity check
if (isUsernameComplex(_text)) {
return "Username can only contain letters and numbers.";
}
// Length check
else if (_text.length < 3 || _text.length > 16) {
return "Username must be between 3-16 characters long.";
}
return null;
}
see if this helps:
List<String> badwords = [
'charlie',
'another_badword',
];
List<String> input = [
'Charlieee',
'Charlie124342',
'Charlie6648',
'213charlie',
'ch1chaRliE32',
'spaghetti',
];
input.forEach((text) {
final bwIndex = badwords.indexWhere(
(badword) => text.toLowerCase().contains(badword),
);
if (bwIndex != -1) {
print('$text is bad word, similar to ${badwords[bwIndex]}');
} else {
print('$text is not a bad word');
}
});

Restricting space at the beginning

This is function which is I'm using at liveChange event:
if (oEvent.mParameters.value.indexOf(" ") === 0) {
sap.m.MessageToast.show("Space character is not allowed");
oEvent.preventDefault();
return false;
}
By using this code I have to restrict the whitespaces at the beginning in the input field. I tried a lot, I'm getting the message but it is taking the whitespace. How can I make an input field display only message and it should not take whitespaces.
To "invasively" remove the whitespace in the beginning of the input, you can do something like this:
onLiveChange = function(oEvent) {
var sValue = oEvent.getParameter('value');
if (sValue[0] === ' ') { // or use sValue.match(/^ /)
oEvent.getSource().setValue(sValue.trimStart());
sap.m.MessageToast.show("Space character is not allowed");
}
}
Also have a look at this SAPUI5 Demokit Sample as well as the validationError and validationSuccess events of class `sap.ui.core.Core' to get an idea of the recommended way of handling validation.

Gtkmm Text Entry filters

I am doing Gtkmm GUI programming now and I am new to this programming language.
How to allow the user to only enter the numeric value in Gtkmm Entry text box.
Use Gtk::SpinButton instead of Gtk::Entry to allow numeric input only.
you need to add a key release signal for your Entry for example this is my entry "m_EntryAmount"
m_EntryAmount.signal_key_release_event().connect(sigc::mem_fun(*this, &Vente::entryKeyReleaseAmount));
and add the signal function
bool Sales::entryKeyReleaseAmount(GdkEventKey* /* event */ )
{
if(m_EntryAmount.get_text()!="" && is_number(m_EntryAmount.get_text()) ){
//now the Entry is not empty and its a number
//do what you want here
}else{
//here the Entry is not a number you can just delete it
m_EntryAmount.set_text("");
}
return true;
}
and add the is_number function
bool Vente::is_number(const string& s)
{
return !s.empty() && std::find_if(s.begin(),
s.end(), [](char c) { return !std::isdigit(c); }) == s.end();
}
this is just a simple example to make an idea about that, you can do it by your self using your way

The 'ArrayIndex' LINQ expression node type is not supported by LINQ to Entities - using interface & ReportViewer

a quick question really.
I'm struggling to implement Linq2Entities statement that could take more than one value for a particular "field". I'm passing a number of strings to the getClientsProjected() I can easily compare single value. But I've got on my page multiple dropdown and out of that I get string separated with coma I then later use to split it to string[] e.g. __ACCOUNT_SITE = "1234,5678" (see the code below) I've tried for/foreach/contains none of which worked...
public IQueryable<ClientViewModel> getClientsProjected(string __ACCOUNT_SITE, string __ACCOUNT)
{
var projectedClients = from c in getClosedSRs()
select new ClientViewModel
{
_ACCOUNT_ID_CSR = c.ACCOUNT_ID_CSR,
_ACCOUNT = c.ACCOUNT,
_ACCOUNT_FAMILY = c.ACCOUNT_FAMILY,
...
...
_ACCOUNT_SITE = c.ACCOUNT_SITE
};
if (String.IsNullOrEmpty(__ACCOUNT) != true && __ACCOUNT != "ALL")
{
//this works fine as an __ACCOUNT is of a single value
projectedClients = projectedClients.Where(c => c._ACCOUNT == __ACCOUNT);
}
if (String.IsNullOrEmpty(__ACCOUNT_SITE) != true && __ACCOUNT_SITE != "ALL")
{
String[] splitSites = __ACCOUNT_SITE.Split(',');
//????????????????????????????????????????????????
}
return projectedClients;
}
Now, to most of you this will make complete sense. I've read many articles but did not find a proper answer. I however can't use Linq2SQL as already built my entire site using L2E, interface and ReportViewer.
Any workaround?
If you are trying to filter projectedClients based on the values in splitSites, then use:
if (String.IsNullOrEmpty(__ACCOUNT_SITE) != true && __ACCOUNT_SITE != "ALL")
{
String[] splitSites = __ACCOUNT_SITE.Split(',');
projectedClients = projectedClients.Where(x => splitSites.Contains(x._ACCOUNT);
}

In KRL, how do I detect if a variable is an array or hash?

In KRL, I'd like to detect whether a variable is an array or hash so that I know if I need to use the decode or encode operator on it. Is that possible?
I'd like to do something like this:
my_var = var.is_array => var.decode() | my_var
Update
The best way to do this is with the typeof() operator. This is new since the answer, but with the early interpretation of variables, the old way listed in the answer will no longer work.
Another useful operator for examining your data is isnull()
myHash.typeof() => "hash"
myArray.typeof() => "array"
...
The only way that I have figured out how to detect the data structure type is by coercing to a string and then checking to see if the resulting pointer string contains the word 'array' or 'hash'.
'One liner'
myHashIsHash = "#{myHash}".match(re/hash/gi);
myHashIsHash will be true/1
Example app built to demonstrate concept
ruleset a60x547 {
meta {
name "detect-array-or-hash"
description <<
detect-array-or-hash
>>
author "Mike Grace"
logging on
}
global {
myHash = {
"asking":"Mike Farmer",
"question":"detect type"
};
myArray = [0,1,2,3];
}
rule detect_types {
select when pageview ".*"
pre {
myHashIsArray = "#{myHash}".match(re/array/gi);
myHashIsHash = "#{myHash}".match(re/hash/gi);
myArrayIsArray = "#{myArray}".match(re/array/gi);
myArrayIsHash = "#{myArray}".match(re/hash/gi);
hashAsString = "#{myHash}";
arrayAsString = "#{myArray}";
}
{
notify("hash as string",hashAsString) with sticky = true;
notify("array as string",arrayAsString) with sticky = true;
notify("hash is array",myHashIsArray) with sticky = true;
notify("hash is hash",myHashIsHash) with sticky = true;
notify("array is array",myArrayIsArray) with sticky = true;
notify("array is hash",myArrayIsHash) with sticky = true;
}
}
}
Example app in action!