I need a regular expression to validate the mobile number up to 9 digits, if the telephone number starts with 8 otherwise 10 digits needs to be entered.
What is the best way for converting phone numbers into international format (E.164) using Java?
Given a 'phone number' and a country id (let's say an ISO country code), I would like to convert it into a standard E.164 international format phone number.
I am sure I can do it by hand quite easily - but I would not be sure it would work correctly in all situations.
Which Java framework/library/utility would you recommend to accomplish this?
P.S. The 'phone number' could be anything identifiable by the general public - such as
* (510) 786-0404
* 1-800-GOT-MILK
* +44-(0)800-7310658
that last one is my favourite - it is how some people write their number in the UK and means that you should either use the +44 or you should use the 0.
The E.164 format number should be all numeric, and use the full international country code (e.g.+44)
How do I make sure I've got a double and not something else?
int main() {
int flagOk = 0;
double number;
while(!flagOk) {
printf("Put in a double");
scanf("%lf", &number);
if(number == "%lf"); //this want make sure
flagOk = 1;
}
}
I have built a custom form for creating a joining model on a has_many :through relationship. The models look roughly like this:
class Team
has_many :team_members
has_many :members, :through => :team_members
end
class Member
has_many :team_members
has_many :teams, :through => :team_members
end
class TeamMember
belongs_to :team
belongs_to :member
# and this model has some validations too
end
The form I have built is for selecting which members should be in a team. I won't paste the form, but it uses the form_tag method and basically sends an array of hashes which contain a member_id and a squad_number. I then update the database with an action that looks roughly like this (simplified a bit, but you get the jist):
@team.transaction do
@team.team_members = params[:team_members].collect{|tm| @team.team_members.new(tm)}
if @team.save
redirect_to ...
else
render :action => :members
end
end
Everything works great but I am validating the squad_number for uniqueness and numerically. So, when any of those validations fail, how do I get access to them in my view, and how do I ascertain which of the many members it has failed on?
I have a form that has several conditional form elements. For example If x is selected in dropdown a, show/hide textfield a etc..
Is there a plugin for it or do I have to write those conditions manually?
Thanks for your help!
Hi,
Why does the Javascript function call isNaN(123.) return false? Is this a universally acceptable number or will it cause errors downstream?
I'm validating whether a value is a valid decimal using isNaN along with split. Are there cross-browser issues with isNaN? Should I use a bespoke implementation?
Thanks.
Ok steps to reproduce this:
prompt> rails test_app
prompt> cd test_app
prompt> script/generate model event_service published:boolean
then go into the migration and add not null and default published to false:
class CreateEventServices < ActiveRecord::Migration
def self.up
create_table :event_services do |t|
t.boolean :published, :null => false, :default => false
t.timestamps
end
end
def self.down
drop_table :event_services
end
end
now migrate your changes and run your tests:
prompt>rake db:migrate
prompt>rake
You should get no errors at this time. Now edit the model so that you validate_presence_of published:
class EventService < ActiveRecord::Base
validates_presence_of :published
end
Now edit the unit test event_service_test.rb:
require 'test_helper'
class EventServiceTest < ActiveSupport::TestCase
test "the truth" do
e = EventServer.new
e.published = false
assert e.valid?
end
end
and run rake:
prompt>rake
You will get an error in the test. Now set e.published to true and rerun the test. IT WORKS! I think this probably has something to do with the field being boolean but I can't figure it out. Is this a bug in rails? or am I doing something wrong?
Is there any existing Python library that can validate data in Excel format? Or what kind of keyword should I use to search such an open source project? Thanks.
I have a projects resource that has many tasks. I want to ensure that every task has a project_id by adding validates_presence_of :project_id to the tasks model.
However, when creating a new project with tasks, the project_id won't be available until the record saves, therefore I can't use validates_presence_of :project_id.
So my question is, how do I validate presence of project_id in the task model? I want to ensure every task has a parent.
...
class Project < ActiveRecord::Base
has_many :tasks, :dependent => :destroy
accepts_nested_attributes_for :tasks, :allow_destroy => true
...
class Task < ActiveRecord::Base
belongs_to :project
validates_presence_of :project_id
Today I asked myself how can I handle user input if the user have not to enter it...
A firstname and lastname is all he must enter. The adress he needs not to fill out.
Now I have to decide, is the missing data a user mistake or didn`t the user want to enter
data?
How can I deal with such a scenario?
May websites, including professional ones usually have a "W3C Markup Validator" and "W3C CSS Validator." Why do you put them there? Is it just pride or is it justified? If it is more than pride, what justifies them?
I have an input field in a form. Upon pushing submit, I want to validate to make sure the user entered non-latin characters only, so any foreign language characters, like Chinese among many others. Or at the very least test to make sure it does not contain any latin characters.
Could I use a regular expression for this? What would be the best approach for this?
I am validating in both javaScript and in PHP. What solutions can I use to check for foreign characters in the input field in both programming languages?
Hi all,
On a Salesforce.com opportunity I have a number of custom fields that are potential options that the end client will eventually select.
Option 1 (Desc Field) Option 1 (Value)
Option 2 (Desc Field) Option 2 (Value)
Option 3 (Desc Field) Option 3 (Value)
At a future point the user will ultimately choose one of the options as the preferred option. What I want is then the value for the chosen option to be stored in another field without the user having to enter it again. A “nice to have” would also be that all 3 option descriptions, values and selected value are locked once this is done.
Any ideas?
I have asp:RegularExpressionValidator with ValidationExpression="\d+{1,4}(?:[.,]\d{1,4})?" but it doesn't' work, parser throws ArgumentException:
parsing "\d+{1,4}(?:[.,]\d{1,4})?" -
Nested quantifier {.
Where is my mistake? I want to allow strings like xxxx,xxxx - from 1 to 4 digits and decimal digits are not required, e.g.: 1000, 99,99, 0,2498, etc.
I dynamically add some elements to a form so I know I need to re-parse the form.
Even if I have old invalid elements they don't get identified in numberOfInvalids
It always comes back = 0 even though the invalid fields are highlighted on the page.
var form = $("#form");
//Form Savingform.submit(function (e) {
e.preventDefault();
form.removeData("validator");
form.removeData("unobtrusiveValidation");
$.validator.unobtrusive.parse(form);
var val = form.validate();
if (val.numberOfInvalids() == 0) {
$.blockUI({ fadeIn: 1000 });
AjaxRequest({
data: $(this).serializeArray(),
success: function (data, status, xhr) { alert('sucess save or submit, use "'); },
complete: function () { $.unblockUI(); }
});
}
});
I just need to validate 2 strings in javascript.
One of them must contain only 0 or more open parenthesis ( .
The other must contain only 0 or more close parenthesis ) .
This means only those characters are allowed in each value.
After spending a lot of time trying to understand the regex, I can't find a way to achieve this. With the escape characters I make a mess of the regex function.
This is what I thought:
/\(*/
Could anyone help me?
heres my code -
function Validate_URL(url) {
var iurl = url.value;
var v = new RegExp();
v.compile("/^(((ht|f){1}(tp:[/][/]){1})|((www.){1}))[-a-zA-Z0-9@:%_+.~#?&//=]+$/;");
if (!v.test(iurl.value)) {
url.style.backgroundColor = 'yellow';
}
return true;
}
no matter what i put in url, say http://www.abc.com/newpage.html, it returns false. how come?
If I have a pointer, like char* foo, is there any way to determine if foo points to a valid location in memory? (So, foo is not NULL, and delete has not yet been called on it.)
For example, you send an unsubscribe message to a legitimate company or a spam, they reply that they will remove you and it may take up to 72 hours to take effect. I find it hard to believe anything that simple could take more than 3/4 of a second to take effect system wide.
Another example would be when you call the visa activation line, there is a "delay" of several minutes while they try to sell you some kind of insurance. Usually just as you get the point across that you don't want it they will tell you your card has been activated and let you go.
Are these delays real?
So I need to get value false or true if string contains not only letters of all european and east alphabets and " "(space) and "-" minus. How to do such thing with some $a string?
I am a beginner in jQuery and I was wondering how to validate the form before submission specifically for check boxes.
I am creating a simple check list form where my user would tick a check box if he finished that step. What I am planning to do is that, the script would prevent the form submission if there is an "unticked" checkbox and highlight it with a color.
Here's my code :
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>checkbox</title>
<style>
.error {
background-color:#F00;
}
.valid {
background-color:#0F0;
}
</style>
<script type="application/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"> </script>
<script type="application/javascript">
function validateAll() {
$(".tick").change(function(){
if ($('.tick:checked').length == $('.tick').length) {
$('#container').removeClass();
$('#container').addClass('error');
} else {
$('#container').removeClass();
$('#container').addClass('valid');
}
});
}
</script>
</head>
<body>
<div id="container"><input class="tick" id="option1" type="checkbox"></div>
<div id="container"><input class="tick" id="option1" type="checkbox"></div>
<input id="button" type="button" onClick="validateAll();" value="check">
</body>
</html>
So what I am trying to do here is when the user clicks the button, the script will highlight all the unchecked check box with red and highlight all checked with green.
However, my script is not functioning. What is wrong with my script? Any suggestions on a more efficient way to do this?
My web page content is populated by a plain text that is retrieved from a CDATA format - plain text data.
This is the site http://checksite.apsx to get information.
For more information, visit http://moresites.com/FAQ/index.html or search the site.
Now, my goal is to convert this plain text to a valid hyperlinks.
I've used a javascript code that does the conversion - /((http|https|ftp):\/\/[^ ]+)/g;
, but sometimes if there are multiple words, it captures an invalid URL.
My question: Is there a way to strictly capture any string that starts with "http" AND ends with ".html" or "aspx" will be converted into a valid hyperlink?
it should look like this -
This is the site http://checksite.apsx to get information.
For more information, visit http://moresites.com/FAQ/index.html or search the site.
I have a model-driven Struts Web action:
public class ModelDrivenAction<T extends Object> implements ModelDriven<T>, Preparable {
protected Long id;
protected T model;
@Override
public void prepare() {}
public void setId(Long id) { this.id = id; }
@Override
public T getModel() { return model; }
public void setModel(T model) { this.model = model; }
}
I have another action which is not currently model-driven:
public class OtherAction implements Preparable {
private ModelObj modelObj;
private Long modelId;
@Override
public void prepare() { modelObj = repoService.retrieveModelById(modelId); }
public void setModelId(Long modelId) { this.modelId = modelId; }
}
I wish to make it so, and would like to avoid having to track down all the instances in JavaScript where the action is passed a "modelId" parameter instead of "id" if at all possible. I thought this might work, so either modelId or id could be passed in:
public class OtherAction extends ModelDrivenAction<ModelObj> {
@Override
public void prepare() { model = repoService.retrieveModelById(id); }
public void setModelId(Long modelId) { this.id = modelId; }
}
However, server/path/to/other!method?modelId=123 is failing to set id. I thought so long as a setter matched a parameter name the Struts interceptor would call it on action invocation. Am I missing something here?