Validate/Restrict zalgo texts in Javascript - unicode

Can I validate a user from entering zalgo texts to a form or any other place which prompts a data save, as explained in [Zalgo Texts]: How does Zalgo text work?

As per your need you can use the following to validate a string as such.
Furthermore you can use strip-combining-marks if you want to remove Unicode combining marks from strings.
function validateZalgo(s) {
return /[^\u+0300-\u+036F]/.test(s);
}
var isValidated = validateZalgo('asd̨͈̺̱̤͚̤͚̤͚͈̆̆̆̆̆̆̆̆̆̆');
alert(isValidated);

Related

give fetched data value to the xpath field in selenium [duplicate]

When I enter text into the text field it gets removed.
Here is the code:
String barcode="0000000047166";
WebElement element_enter = _driver.findElement(By.xpath("//*[#id='div-barcode']"));
element_enter.findElement(By.xpath("//html/body/div[1]/div[3]/div[1]/form/div/div/input")).sendKeys("barcode");
Agree with Subir Kumar Sao and Faiz.
element_enter.findElement(By.xpath("//html/body/div[1]/div[3]/div[1]/form/div/div/input")).sendKeys(barcode);
I had a case where I was entering text into a field after which the text would be removed automatically. Turned out it was due to some site functionality where you had to
press the enter key after entering the text into the field. So, after sending your barcode text with sendKeys method, send 'enter' directly after it. Note that you will have to import the selenium Keys class. See my code below.
import org.openqa.selenium.Keys;
String barcode="0000000047166";
WebElement element_enter = driver.findElement(By.xpath("//*[#id='div-barcode']"));
element_enter.findElement(By.xpath("your xpath")).sendKeys(barcode);
element_enter.sendKeys(Keys.RETURN); // this will result in the return key being pressed upon the text field
I hope it helps..
Use this code.
driver.FindElement(By.XPath(".//[#id='header']/div/div[3]/div/form/input[1]")).SendKeys("25025");
It might be the JavaScript check for some valid condition.
Two things you can perform a/c to your requirements:
either check for the valid string-input in the text-box.
or set a loop against that text box to enter the value until you post the form/request.
String barcode="0000000047166";
WebElement strLocator = driver.findElement(By.xpath("//*[#id='div-barcode']"));
strLocator.sendKeys(barcode);

Kentico Phone Format not consistent

I'm adding a US phone number to a form in Kentico 9 but the format is not consistent. When I create my form in the Form Builder it looks like this:
Well Formatted US phone format
However when I view the form it Kentico splits up the phone number into it's component parts and places them all on one line. I'm not finding a place to fix this. Seems like a silly way to work...
Bad Phone image
I've tried creating Custom Layouts but it doesn't appear to allow you to control the format there.
I am not sure if I understand you right - you have a form with field (Data type: text) which is using U.S. phone number form control. You can specify proper behavior in ~/CMSFormControls/Inputs/USphone.ascx (default path where are files for this form control). You can specify css classes in USphone.ascx and general behavior in USphone.ascx.cs file. Please note this property:
public override object Value
{
get
{
if (IsEmpty())
{
return String.Empty;
}
return String.Format("({0}) {1}-{2}", txt1st.Text, txt2nd.Text, txt3rd.Text);
}
.
.
.
}
In return there is specified way you are formatting text - this might help you to achieve your desired behavior.

Yii2 remove empty fields from url string

I need your help. I have an Active Form in my Yii2 application and when I submit my form it shows values (no matter empty or not) of every field of the form to the GET-string so it looks like
domain.com/index?ItemSearch%5Brooms_arr%5D=&ItemSearch%5Bprice_type%5D=& ItemSearch%5Bprice_type%5D=0&ItemSearch%5Barea_from%5D=&ItemSearch%5Barea_to%5D=&... etc.
I need to have cleaner query string which will contain only non-empty params?
For example domain.com/index?rooms_arr=12&price_type=normal.
Please suggest me what is the best way to do this?
This is not the yii2 problem. It is a native html form works like this. If you really do want to exclude all not filled inputs from the query string you could filter all this params via jQuery and set them to disable state, here is the code
$('form').submit(function(e){
var emptyinputs = $(this).find('input').filter(function(){
return !$.trim(this.value).length; // get all empty fields
}).prop('disabled',true);
});

silverstripe backend linebreaks in content do not show up in frontend

I have a textareaField in Silverstripe Backend in Edit Page View... The text to insert contains linebreaks. If I save the Page the text shows correctly with linebreaks in the textareaField. The linebreaks are for sure saved correctly to the database. But how do I display the text correctly in the frontend? It´s always outputted without linebreaks in a single line.
I tried already $Text.RAW, $Text.XML,... nothing works.
Thanks for the help,
Kind regards,
Florian
Assuming that you are using 3.0 this is a bug. You can see it here http://open.silverstripe.org/ticket/7596
A work around is to write your own function calling nl2br on your text field.
Here is an example:
public function NiceDescription () {
return (nl2br (Convert::raw2xml ($this->Description), true));
}
You can replace "Description" with the name of your text property.
Then in your template file if you need to display the description field you will call the function:
$NiceDescription
to visually render the newlines in html, you need to convert them to <BR> tags.
see http://php.net/manual/de/function.nl2br.php

Problem about the customised validation rule using regular expression in JQuery

I have a form having some text boxes, radio buttons, and select boxes. I write custom validation methods which i added using validator.addmethod.
If user submitted this form keeping some or all fields empty then form should get submitted but if user enters data in text boxes then data should be alphabetic and should not contain special character and numbers.
I write validation code for some text boxes for which the custom validation code as I mentioned above is as follows.
$.validator.addMethod('specialchar', function (value) {
return /^[^a-zA-Z]$/.test(value);
}, 'First Name should not contain special characters.');
**Now actually when user submits form with empty fields then error messages of above custom validation method is displayed for those textboxes to which above method is assigned **
I think there is also problem in my regular expression which i can not able to spot.
If my regular expression is right then is there any other method to add regular expression in JQuery i.e. lookahed regular expression.
Please help me on these two problems guys
Thank You
Maybe something more like this:
/^[^a-zA-Z]{0,}$/