validation

How to check empty element in json

谁都会走 提交于 2021-01-29 02:09:15
问题 Is there any way in scala/java to evaluate if all items in a JSON are not empty? I would like to have a validator, avoiding to have items in a json with empty values like: [{"elem1":"","elem2":"","elem3":"a"}] Where the first two elements are empty. 回答1: Using Play JSON: import play.api.libs.json._ def hasEmptyValue(json: JsValue): Boolean = { json match { case _: JsBoolean => false case _: JsNull => false // could also be true, depending on your definition case _: JsNumber => false case

How to check empty element in json

╄→尐↘猪︶ㄣ 提交于 2021-01-29 02:05:54
问题 Is there any way in scala/java to evaluate if all items in a JSON are not empty? I would like to have a validator, avoiding to have items in a json with empty values like: [{"elem1":"","elem2":"","elem3":"a"}] Where the first two elements are empty. 回答1: Using Play JSON: import play.api.libs.json._ def hasEmptyValue(json: JsValue): Boolean = { json match { case _: JsBoolean => false case _: JsNull => false // could also be true, depending on your definition case _: JsNumber => false case

CouchDB: add timestamp on insert and update

隐身守侯 提交于 2021-01-28 22:18:51
问题 How I can add or update timestamp on document when it changes? Currently I have date field, which set from app, but that is not secure and right way if anyone can set time. I'm tried with validate_doc_update , but no luck: it don't save newDoc changes. 回答1: In order to do this, you need to send all your changes through update handlers. To be clear, that means normal writes to the database will not set these timestamps, so you can only reliably do this if your database isn't exposed publicly.

Implement data validation in entity framework code first

扶醉桌前 提交于 2021-01-28 19:49:26
问题 I am using entity framework 6, .Net framework 4 and code first. I am able to get the validation errors by using GetValidationResult method. But I was not able to show the validation message like the one given in the below image. How to achieve this? My Code: <Label Content="Name" /> <Grid Grid.Row="0" Grid.Column="2"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <TextBox x:Name="txtName" Width="200" Margin="8,0,0,0" MaxLength="150" Text="{Binding Path

regex for alphanumeric only is not working

元气小坏坏 提交于 2021-01-28 19:30:15
问题 This is the code I am trying: string MatchNumberPattern = "^[a-zA-Z0-9]*$"; if (!Regex.IsMatch(cueTextBox9.Text, MatchNumberPattern)) { MessageBox.Show("Enter 8 Space Alphanumeric BT ID only"); cueTextBox9.Text = String.Empty; } else { do something(); } It's accepting aaaaaaaa , but I want a combination of both alpha and numbers like aaaa1234 . 回答1: To require both a letter and a digit to appear in the input, you need positive lookaheads : @"^(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]*$" ^^^^^^^^^^

regex for alphanumeric only is not working

有些话、适合烂在心里 提交于 2021-01-28 19:22:37
问题 This is the code I am trying: string MatchNumberPattern = "^[a-zA-Z0-9]*$"; if (!Regex.IsMatch(cueTextBox9.Text, MatchNumberPattern)) { MessageBox.Show("Enter 8 Space Alphanumeric BT ID only"); cueTextBox9.Text = String.Empty; } else { do something(); } It's accepting aaaaaaaa , but I want a combination of both alpha and numbers like aaaa1234 . 回答1: To require both a letter and a digit to appear in the input, you need positive lookaheads : @"^(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]*$" ^^^^^^^^^^

Asp MVC Model Entity Validation does not displaying Required Error

こ雲淡風輕ζ 提交于 2021-01-28 19:07:00
问题 I want to validate a form via Model Entity Required Attribute. I have Declared Required Attribute in Db Model Class, but not able to view the validation error when the filed remains empty, However the data is inserted into Db if the form fields are not empty but when they are empty no Validation Error occurs. Here is my Model Class Code: namespace MVCLogin.Models { using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; public

Codeigniter- How to preserve form values if error on submit

情到浓时终转凉″ 提交于 2021-01-28 18:38:25
问题 I have the form field like <input type="text" class="form-control" name="postal_code" id="form_control_1" value="<?php if($user->postal_code === NULL) { echo set_value('postal_code');} else { echo $user->postal_code;} ?>"> <label for="form_control_1">Postal Code</label> <span class="help-block">Postal Code is required</span> and my function is public function postProfile() { if ($_POST) { $this->form_validation->set_rules('postal_code', 'Postal Code', 'required'); $this->form_validation->set

Limit the amount of characters typed into a JTextField [duplicate]

别等时光非礼了梦想. 提交于 2021-01-28 15:26:36
问题 This question already has answers here : Limiting TextField inputs (2 answers) Closed 6 years ago . I figured this would be a simple search on the web but I can't figure this out. Here is what I'm working with so far. Ignore the eventHandler, I know its empty. I want to limit the charField JTextField so that the user can only type one character. I figured this would be easy because of all the apps that limit the amount of numbers you can type when entering State or Zipcode. To be clear, I'm

MongoError: Document failed validation - How to insert both float and int into the same field - which is marked as double?

寵の児 提交于 2021-01-28 14:45:44
问题 I'm having problems with inserting into mongoDB because good objects don't pass the mongoDB validator . To make it worse, the error is a generic: Document failed validation which in a big multi-nested object can make things confusing regarding where exactly this validation fails. myValidatorIs = { validator: { $jsonSchema : { bsonType: "object" , required: [ "price" ] , properties: { price: { bsonType: "double" // price needs to be a double, tried with decimal also. , description: "must be a